1,获取url值。

        public ActionResult About()
        {
           RouteValueDictionary RVD 
= new RouteValueDictionary();
            RVD[
"myname"]="wtq";

            ViewData[
"url"= Url.RouteUrl("myname", RVD);
            
return View();

        }

 2,在global.ascx文件中配置url路径。

public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute(
"{resource}.axd/{*pathInfo}");
            routes.MapRoute(
          
    "myname"// 路由名称 通过路由名称来获取该url。
              "wo-de-ming-zi-jiao-zuo-wtq{myname}.html"// 带有参数的 URL
              new { controller = "Home", action = "Index", id = UrlParameter.Optional } // 参数默认值
          );
            routes.MapRoute(
                
"Default"// 路由名称
                "{controller}/{action}/{id}"// 带有参数的 URL
                new { controller = "Home", action = "Index", id = UrlParameter.Optional } // 参数默认值
            );
           
        }

 

3.在前台显示连接

  <h2>关于</h2>
    
<p>
        将内容放置在此处。
        
<a href="<%=ViewData["url"] %>">zheshi cong url huoqu de lianjie</a>  这里的数据是从controller中来的。
    
</p>

 

这样就可以搞定了。

总结:在做网站时,可以通过该方法动态的生成url。

相关文章:

  • 2021-11-20
  • 2021-05-25
  • 2021-06-10
  • 2021-12-28
  • 2021-12-31
  • 2022-02-01
猜你喜欢
  • 2021-09-21
  • 2021-12-05
  • 2021-11-20
  • 2022-01-22
  • 2021-08-11
  • 2021-11-20
相关资源
相似解决方案