Authour: |
Chenboyi |
UpdateTime: |
2015-04-27 22:32:47 |
Friendly Link: |
|
1,codesimple:
PS: Because urlhelper involves less knowledge, directly on the source demo
Compared to the traditional <a herf= "/mycontroller/index" > Jump </a> this notation,
<a herf= "@Url. Action (" Index "," Mycontroller ")" > Jump </a> has a small advantage, that is, it is a matching routing rule;
Url.encode (); transcode the URL to return a string.
1 <!--urlhelper.cshtml - 2 <Div>3 <HR/>4 @*url.action (): Generates a URL focus based on the URL placeholder in the routing rule according to the specified parameters *@ 5 @url.action ("Add", new {controller = "Urlhelperdemo", id = +})6 <BR/>7 url.encode= @Url. Encode ("http://www.baidu.com/News/a.aspx?id= Eight commandments")8 <BR/>9 @{Ten var s = server.urldecode (Url.encode ("http://www.baidu.com/News/a.aspx?id= Eight Commandments")); One @s A } - <BR/> - @* Specifies a route rule to generate the corresponding URL key *@ the @url.routeurl ("Default1", new {controller = "Home", action = "index", id = 100,name= "eight Commandments"}) - <BR/> - <ahref= "@url.action ("Add ", new {controller= "Urlhelperdemo", id=})">Jump</a> - <BR/> + <ahref= "@url.routeurl ("Default1 ", new {controller= "Home", Action= "Index", id= 100,name= "Eight commandments"})">Jump</a> - </Div>
The Urlhelper in MVC