Html.partial method and Html.renderpartial method

Source: Internet
Author: User

The distributed view Partialview is generally functionally independent, and a view snippet similar to a user control can be referenced by multiple views, as follows.

1,html.partial method and Html.renderpartial method

Static class System.Web.Mvc.Html.PartialExtensions, using the extension method, expands the System.Web.Mvc.HtmlHelper, So with the Html.partial method, the method returns a value of Mvchtmlstring

The static class System.Web.Mvc.Html.RenderPartialExtensions, using the extension method, expands the System.Web.Mvc.HtmlHelper, and therefore has the Html.renderpartial method, Method has no return value (void)

All two of the above methods load partial views, but they are not used the same way

Html.partial returns mvchtmlstring, so you can call it in the form of an razor expression

@Html. Partial ("ViewName")

Html.renderpartial does not have a return value, so it is called as an embedded snippet and cannot be used with a razor expression

@{            html.renderpartial ("ViewName");    

The above two methods, instead of invoking the Controller's action, are loaded directly based on the specified partial view name.

The default search path for the distribution view is/views/the current controller and/views/shared folder.

2,html.action method and Html.renderaction method

System.Web.Mvc.Html.ChildActionExtensions, extending the System.Web.Mvc.HtmlHelper with the extension method, thus having the action and Renderaction methods,

The Html.action method returns mvchtmlstring, so you can invoke it using the razor expression

@Html. Action ("actionName","childcontrollername")

Html.renderaction does not have a return value (void), so it needs to be put in a code snippet

@{html.renderaction ("actionname","childcontrollername ");}

The above two methods require a mate controller and method (Action)

method returns the Partialviewresult instance (the Controller.partialview () method returns this instance)

These two methods can be used when the calling procedure contains business processing logic.

Html.partial method and Html.renderpartial method

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.