现在的位置: 首页 > 综合 > 正文

MVC Rounting System 学习心得(二)

2012年09月11日 ⁄ 综合 ⁄ 共 523字 ⁄ 字号 评论关闭

1.Generating Outgoing URLs in Views  
Rules:

  routes.MapRoute("MyRoute", "{controller}/{action}/{id}", 
                new { controller = "Home", action = "Index",  
                    id = UrlParameter.Optional }); 
        } 

View:

 

  1.  <div> 
            @Html.ActionLink("This is an outgoing URL", "CustomVariable") 
        </div> 

    Html:

    <a href="/Home/CustomVariable">This is an outgoing URL</a> 
    
 routes.MapRoute("NewRoute", "App/Do{action}", 
        new { controller = "Home" }); 

Html:

<a href="/App/DoCustomVariable">This is an outgoing URL</a>

2.Generating Outgoing URLs in Views  

It's not a link, just a literal string.

 @Url.Action("Index", "Home", new { id = "MyId" }) 

 

抱歉!评论已关闭.