在 ascx 文件中使用 Html.RenderPartial()
我正在尝试在 acsx 文件中使用 Html.RenderPartial 我收到一个错误:
编译器错误消息:CS1973:“System.Web.Mvc.HtmlHelper” 没有名为“RenderPartial”的适用方法,但似乎有一个 使用该名称的扩展方法。扩展方法不能是动态的 已派遣。考虑强制转换动态参数或调用 没有扩展方法语法的扩展方法
<a href="/projects/<%=project.Id %>">
<% Html.Label("fdf"); %>
<% Html.RenderPartial("ProjectName", Model.Id); %></a></li>
<%} %>
但是我已经导入了必要的命名空间,因此不会出现错误
<% Html.Label("fdf"); %>
Are There are there anymethods to use Html.RenderPartial in ascx file?
I'm trying to use Html.RenderPartial in acsx file
and I'm getting an error:
Compiler Error Message: CS1973: 'System.Web.Mvc.HtmlHelper'
has no applicable method named 'RenderPartial' 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
<a href="/projects/<%=project.Id %>">
<% Html.Label("fdf"); %>
<% Html.RenderPartial("ProjectName", Model.Id); %></a></li>
<%} %>
However I've import neccessary namespaces, so it won't be error at
<% Html.Label("fdf"); %>
Are there any methods to use Html.RenderPartial in ascx file?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
编译器无法选择正确的方法,因为您的模型是
动态
。将调用更改为:或 Id 的任何其他数据类型。
The compiler cannot choose the correct method because your Model is
dynamic
. Change the call to:Or any other datatype Id is.
如果其他人犯了与我相同的错误:
这会将您的模型视为动态
这是一个正确的强类型视图。注意大小写的缺失!
请注意,这是 Razor,与原来的问题不同。
In case anyone else made the same mistake I did:
This will treat your model as dynamic
This is a correctly strongly typed view. Note the lack of capitalisation!
Note, that this is Razor, unlike the original question.
我发现通过的唯一方法,例如。 IEnumerable 的作用是创建一个局部变量并传入该变量。;朋友=模型.朋友;
例如
<代码>@{
IEnumerable
Html.RenderPartial("_FriendsList", 朋友);
}
Html.RenderPartial("_FriendsList", (IEnumerable)(Model.Friends));
不起作用!The only way i found to pass eg. an IEnumerable was to create a local variable and pass in this one.
For Example
@{
IEnumerable<Demo.Models.Friend> friends = Model.Friends;
Html.RenderPartial("_FriendsList", friends);
}
Html.RenderPartial("_FriendsList", (IEnumerable<Demo.Models.Friends>)(Model.Friends));
did not work!