MVC Rounting System 学习心得(二)

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" }) 

 

posted @ 2013-05-26 23:53  chunchill  阅读(230)  评论(0编辑  收藏  举报