asp.net MVC key Tutorial First anniversary edition seventh back Urlhelper

Source: Internet
Author: User
Tags new features

This section is about the helper in asp.net mvc.

What is helper is actually a group of methods written in view to implement some flexible functions.

In fact, asp.net mvc view is the ASPX page, itself can declare the definition method, then why should there be helper?

Instead of just separating the interface from the logic, ASP.net MVC does not support only the ASPX view (which can be extended much), but also the castle Nvelocity engine and Boo, and Viewspark pages in the expansion pack.

So, if you define a method in aspx, it can affect extensibility and portability. And the code doesn't look too good.

First, Urlhelper.action

The Urlhelper action method is used to generate a hyperlink that uses the

Current controller index This Action <%=url.action ("index")%> index

Current controller index This Action <%=url.action ("Index", new{id=1})% > Index?id=1

Eicecontroller under Index this Action <%=url.action ("Index", "Eice")%>/eice/index

Eicecontroller Index This Action <%=url.action ("Index", "Eice", new{id=1})%>/eice/index?id=1

For example, I write Url.action ("Index", "Home") in the view, and when I run it generates/home/index this address, and if the URL routing rules in your system always change, the helper is the one you must choose.

Second, Urlhelper.encode

This is also a method of urlhelper using methods such as <%=url.encode ("Chinese")%> function is the same as Server.URLEncode, there is not much to say

Third, urlhelper.content

Used for server path conversion to absolute path.

Such as

<%=Url.Content("~/content/site.css") %>

The final result is

/content/site.css 

If you have special needs, you can use 3.0 new features, extension methods to add new features for Urlhelper, and in the next section we'll talk about how to use helper to display HTML

Related Article

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.