gpt4 book ai didi

c# - 来自 RAZOR 中不同文件夹的 RenderPartial

转载 作者:可可西里 更新时间:2023-11-01 08:32:17 27 4
gpt4 key购买 nike

我一直在尝试将我的 aspx 页面转换为 cshtml,但在从另一个文件夹呈现部分页面时遇到问题。

我曾经做过的事情:

<% Html.RenderPartial("~/Views/Inquiry/InquiryList.ascx", Model.InquiryList.OrderBy("InquiryId", MvcContrib.Sorting.SortDirection.Descending));%>

我认为等同于:

@Html.RenderPartial("~/Views/Inquiry/_InquiryList.cshtml", Model.InquiryList.OrderBy("InquiryId", MvcContrib.Sorting.SortDirection.Descending))

这显然不起作用,我收到以下错误。

CS1973: 'System.Web.Mvc.HtmlHelper' has no applicable method named 'Partial' but appears to have an extension method by that name. Extension methods cannot be dynamically dispatched. Consider casting the dynamic arguments or calling the extension method without the extension method syntax.

我如何使用 Razor View 引擎实现这一点?

最佳答案

RenderPartial不返回字符串或 IHtmlString 值。但是通过在 Response 中调用 Write 来进行渲染。

您可以使用 Partial扩展,这将返回一个 MvcHtmlString

 @Html.Partial( ....

 @{ Html.RenderPartial(....);  }

如果你真的想要RenderPartial

关于c# - 来自 RAZOR 中不同文件夹的 RenderPartial,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4524267/

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