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