This section describes helper in ASP. net mvc.
Helper is actually a method group written in view to implement some flexible functions.
In fact, ASP. net mvc view is An ASPX page, which can declare the definition method. Why is there a helper?
In fact, it is nothing more than separating the interface from the logic, and Asp.net MVC does not only support aspx view (it can be expanded a lot). In the extension package, there are also Castle's nvelocity engine and Boo, as well as viewspark pages.
Therefore, defining a method in aspx affects its scalability and portability.CodeNot very nice.
1. urlhelper. Action
UrlhelperThe action method is used to generate a URL address.
The action <% = URL. Action ("Index") %> index under the current controller
The action <% = URL. Action ("Index", new {id = 1}) %> index? Id = 1
Eicecontroller index action <% = URL. Action ("Index", "eice") %>/eice/Index
The action <% = URL. Action ("Index", "eice", new {id = 1}) %>/eice/index? Id = 1
For example, I write a URL in the view. action ("Index", "home"). After running, the address/home/index is generated, if the URL routing rules in your system are always changing, This helper is a required choice.
Ii. urlhelper. encode
This is also a method for using urlhelper. For example, the <% = URL. encode ("Chinese") %> function is the same as server. urlencode.
3. urlhelper. Content
Converts a server path to an absolute path.
For example
<%= URL. Content ("~ /Content/site.css ")%>
The final result is
/Content/site.css
If you have special requirements, you can use the new 3.0 feature and Extension Method to add new features for urlhelper. The next section describes how to use helper to display HTML