@Html. Action ()

Source: Internet
Author: User

How to use: @Html. Action (action, Controller)
Loads a partial page.
For example, use in a template page: @Html. Action ("Contact", "Company")
In Companycontroller, there are the following methods:
Public Partialviewresult Contact ()

{
return Partialview ();
}

@html.partial,@html.action,@html.renderpartial,@html.renderaction differences in ASP. NET MVC
make a summary of these four differences, clean up your ideas and facilitate future applications:

1, with the method of the render return value is void, the output within the method; The return value type is mvchtmlstring, so it can only be applied as follows:
@html.partial corresponds to @{html.renderpartial (...). );}
@html.action corresponds to @{html.renderaction (...). );}


2, Action, renderaction loading method of the view, to fulfill the order of Controller→model→view, and then the resulting page back to the original view and then return. Partial and renderpartial directly load the contents of the view file


3. Html.partial can directly supply the user control name as a parameter, and html.action needs a corresponding action to return Partailresult (that is, Retun Partialview ()) within the action.


4, for simple user control without any logic, recommended application html.partial; For user controls that need to have some model set, it is recommended to apply html.action. Of course, there are model data can also be applied html.partial method, you can see the method of overloading.


5, the application of html.action has a benefit, that is, you can select the appropriate user control according to the scene. Like what:
@html.action ("Userinfocontrol")
In the corresponding Userinfocontrol this action, when the user is not logged in, you can Retun Partialview ("Logonusercontrol"), after logging in, you can Retun Partialview (" Userinfocontrol ");



@Html. Action ()

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.