Go Html.partial, renderpartial, action,renderaction differences and usages in ASP.

Source: Internet
Author: User

Partial and RenderPartial:
Both of the properties are the same, only refers to a view to the inlay in, but the return value is a little different
An object (mvchtmlstring) that returns a string to return a bunch of HTML, and then writes it to the main page.

@Html. Partial ("ViewName")

The renderpartial callback is void, and this method adds the specified view to the main page

@{
Html.renderpartial ("ViewName");
}

These two methods do not use the controller, is to directly put a view (Page) to add in
and renderaction a bit different, this is an action, so will use the controller and then return a page

public class Childactiononlytestcontroller:controller

{

[Childactiononly]

Public ActionResult getsupplierlist ()

{

var controller = new Suppliercontroller ();

Return controller. Supplierlist ();

}

}

renderpartial and RenderactionThe same point of the two

are often used to display a relatively independent "block", such as a menu or a navigation bar. The results of both outputs are displayed as part of the view that is called.

Different points of the two
    1. Renderpatial's data comes from the calling view, and Renderaction comes from itself.
    2. Renderaction will initiate a new request, and renderpatial will not.

@Html. partial/@{htmt.renderpartial ()}@Html. Partial to render a partial view as a string @{html.renderpartial} writes the distribution view directly to the response output stream, so it can only be placed directly in the code block, not in the expression (the return value is void) RenderPartial because it is written directly in the response stream, the performance is better (micro-impact), and the partial is not written in the code block, so it is more convenient @Html. Action ()/@Html. Renderaction ()and partial are similar to renderpartial, but because they pass action, they are more flexible and can take advantage of the controller context. In action, you can use the ischildaction to determine whether it is called directly by the URL or by the action ()/renderaction () call to take advantage of the overloaded direct arguments to the action. Renderaction preferred to use Actionnameattribute. Use return Partialview () in the action to specify the partial view, and the layout specified in _viewstatrt.cshtml will not be valid. 4 Kinds of Partialview contrast:
Partialview:
<div>just a Partialview [email protected]</div> @ViewBag. Test

View:
<p>    @{html.renderpartial ("ViewUserControl1");}    @Html. Partial ("ViewUserControl1")    @{html.renderaction ("ViewUserControl1");}    @Html. Action ("ViewUserControl1") </p>

Controller:
controller:[childactiononly]//prevents direct call to public ActionResult ViewUserControl1 () {    viewbag.test = "(Action) call";    return Partialview ();}

Effect:

Go Html.partial, renderpartial, action,renderaction differences and usages in ASP.

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.