The Urlhelper in MVC

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.