慕田峪7331174
将@Html.Partial看作复制到父页面中的HTML代码。可以将@Html.RenderPartial看作是合并到父页面中的.ascx用户控件。.ascx用户控件的开销要大得多。@html.Partial‘返回与父字符串内联构造的html编码字符串。它访问父母的模型。@Html.RenderPartial‘返回等效的.ascx用户控件。它自己获取页面的ViewDataDictionary副本,而对RenderPartial视图数据所做的更改不会影响父视图数据。利用反射,我们发现:public static MvcHtmlString Partial(this HtmlHelper htmlHelper, string partialViewName, object model, ViewDataDictionary viewData){
MvcHtmlString mvcHtmlString;
using (StringWriter stringWriter = new StringWriter(CultureInfo.CurrentCulture))
{
htmlHelper.RenderPartialInternal(partialViewName, viewData, model, stringWriter, ViewEngines.Engines);
mvcHtmlString = MvcHtmlString.Create(stringWriter.ToString());
}
return mvcHtmlString;}public static void RenderPartial(this HtmlHelper htmlHelper, string partialViewName){
htmlHelper.RenderPartialInternal(partialViewName, htmlHelper.ViewData, null, htmlHelper.ViewContext.Writer, ViewEngines.Engines);}