I've been trying to convert my aspx pages to cshtml and having an issue with rendering partial pages from another folder.
我一直在尝试将我的aspx页面转换为cshtml,并对从另一个文件夹呈现部分页面产生了问题。
What I used to do:
我以前做的:
<% Html.RenderPartial("~/Views/Inquiry/InquiryList.ascx", Model.InquiryList.OrderBy("InquiryId", MvcContrib.Sorting.SortDirection.Descending));%>
I would think that the equivalent would be:
我认为等价的是:
@Html.RenderPartial("~/Views/Inquiry/_InquiryList.cshtml", Model.InquiryList.OrderBy("InquiryId", MvcContrib.Sorting.SortDirection.Descending))
This is obviously not working, I am getting the following error.
这显然不能工作,我得到以下错误。
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.
CS1973:“System.Web.Mvc。HtmlHelper没有“部分”的可用方法,但似乎有一个扩展方法。不能动态分派扩展方法。考虑在没有扩展方法语法的情况下转换动态参数或调用扩展方法。
How would I achieve this with using the Razor view engine?
如何使用Razor视图引擎实现这一点?
3 个解决方案
#1
24
The RenderPartial does not return a string or IHtmlString value. But does the rendering by calling Write in the Response.
RenderPartial不返回字符串或IHtmlString值。但是渲染是通过调用响应中的Write来实现的。
You could use the Partial extension, this returns an MvcHtmlString
您可以使用部分扩展,这将返回一个MvcHtmlString。
@Html.Partial( ....
or
或
@{ Html.RenderPartial(....); }
If you really want RenderPartial
如果你真的想要渲染部分
#2
7
The compiler cannot choose the correct method because your Model is dynamic. Change the call to:
编译器不能选择正确的方法,因为您的模型是动态的。改变调用:
@Html.RenderPartial("~/Views/Inquiry/_InquiryList.cshtml", (List<string>)Model.InquiryList)
Or to whatever data type InquiryList is.
或者到任何数据类型InquiryList。
#3
2
Remember to include your strongly typed @model
directive in your new Razor view. It is an easy step to miss when converting views from .aspx to .cshtml. If you forget, that 'System.Web.Mvc.HtmlHelper' has no applicable method named 'Partial' error message could appear.
记住在新的Razor视图中包含强类型的@model指令。当将视图从.aspx转换为.cshtml时,很容易忽略这一步。如果你忘记了,那就是System.Web.Mvc。HtmlHelper'没有一个名为“部分”错误消息的可应用方法。
#1
24
The RenderPartial does not return a string or IHtmlString value. But does the rendering by calling Write in the Response.
RenderPartial不返回字符串或IHtmlString值。但是渲染是通过调用响应中的Write来实现的。
You could use the Partial extension, this returns an MvcHtmlString
您可以使用部分扩展,这将返回一个MvcHtmlString。
@Html.Partial( ....
or
或
@{ Html.RenderPartial(....); }
If you really want RenderPartial
如果你真的想要渲染部分
#2
7
The compiler cannot choose the correct method because your Model is dynamic. Change the call to:
编译器不能选择正确的方法,因为您的模型是动态的。改变调用:
@Html.RenderPartial("~/Views/Inquiry/_InquiryList.cshtml", (List<string>)Model.InquiryList)
Or to whatever data type InquiryList is.
或者到任何数据类型InquiryList。
#3
2
Remember to include your strongly typed @model
directive in your new Razor view. It is an easy step to miss when converting views from .aspx to .cshtml. If you forget, that 'System.Web.Mvc.HtmlHelper' has no applicable method named 'Partial' error message could appear.
记住在新的Razor视图中包含强类型的@model指令。当将视图从.aspx转换为.cshtml时,很容易忽略这一步。如果你忘记了,那就是System.Web.Mvc。HtmlHelper'没有一个名为“部分”错误消息的可应用方法。