@Html. Partial and @html.action differences

Source: Internet
Author: User

1. First look at their peering relationship

@Html. Partial corresponds to @{html.renderpartial ();}
@Html. Action corresponds to @{html.renderaction ();}

The above statements correspond to each other, they realize the function is the same, the difference is the wording,

View of the 2.Action load method, execute the order of the Controller→model→view, and then return the resulting page back to the original view. Partial directly loads the contents of the view file

[email protected] can directly provide the user control name as a parameter, and html.action need to have a corresponding action, within the action return Partailresult (that is, Retun Partialview ()).

Such as: The following example can illustrate the use of @html.partial

        Public ActionResult Index ()        {            string[] Txtarry = {"1", "2", "3"};            viewdata["txt" = "welcome";            Return View (Txtarry);        }

Index.cshtml page

<body>    <div>        @* here should show: 1*@        @Model [0]    </div>    <div>        @* Call msg1.cshtml*@        @Html. Partial ("MSG1")    </div></body>

If the @html.partial ("MSG1") does not pass a specific value, then it will default to the index in the model value passed, if there is a specific parameter, then the model value in the MSG1 is to pass over the parameter value

such as: @Html. Partial ("Msg1", (object) model[1])

Msg1.cshtml page

<body>    <div>        @Model [0][email protected]["TXT"]    </div></body>

Summary: With @html.partial (page), then this page in the data source is "call page: Index.cshtml" To, as long as the index page can accept the ViewData so MSG1 can accept, The index page is the MSG1 page of the food and clothing parents. Finally, choose according to different uses.

@Html. Partial and @html.action differences

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.