gpt4 book ai didi

asp.net - MVC2 中 Html.Partial(view, model) 和 Html.RenderPartial(view,model) 之间有什么区别(如果有)?

转载 作者:行者123 更新时间:2023-12-03 04:26:08 28 4
gpt4 key购买 nike

除了它返回的类型以及您当然以不同方式调用它的事实

<% Html.RenderPartial(...); %>
<%= Html.Partial(...) %>

如果它们不同,为什么要调用其中一个而不是另一个?
定义:

// Type: System.Web.Mvc.Html.RenderPartialExtensions
// Assembly: System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
// Assembly location: C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 2\Assemblies\System.Web.Mvc.dll

using System.Web.Mvc;

namespace System.Web.Mvc.Html
{
public static class RenderPartialExtensions
{
public static void RenderPartial(this HtmlHelper htmlHelper, string partialViewName);
public static void RenderPartial(this HtmlHelper htmlHelper, string partialViewName, ViewDataDictionary viewData);
public static void RenderPartial(this HtmlHelper htmlHelper, string partialViewName, object model);

public static void RenderPartial(this HtmlHelper htmlHelper, string partialViewName, object model,
ViewDataDictionary viewData);
}
}

// Type: System.Web.Mvc.Html.PartialExtensions
// Assembly: System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
// Assembly location: C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 2\Assemblies\System.Web.Mvc.dll

using System.Web.Mvc;

namespace System.Web.Mvc.Html
{
public static class PartialExtensions
{
public static MvcHtmlString Partial(this HtmlHelper htmlHelper, string partialViewName);

public static MvcHtmlString Partial(this HtmlHelper htmlHelper, string partialViewName,
ViewDataDictionary viewData);

public static MvcHtmlString Partial(this HtmlHelper htmlHelper, string partialViewName, object model);

public static MvcHtmlString Partial(this HtmlHelper htmlHelper, string partialViewName, object model,
ViewDataDictionary viewData);
}
}

最佳答案

唯一的区别是Partial返回 MvcHtmlString ,并且必须在 <%= %> 内部调用,而RenderPartial返回void并直接渲染到 View 。

如果你看source code ,您会看到它们都调用相同的内部方法,并传递一个 StringWriter 供其渲染。

您可以调用Partial如果您想要查看、保存或操作生成的 HTML,而不是将其写入页面。

关于asp.net - MVC2 中 Html.Partial(view, model) 和 Html.RenderPartial(view,model) 之间有什么区别(如果有)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2729815/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com