在 ascx 文件中使用 Html.RenderPartial()

发布于 2024-09-25 09:19:04 字数 598 浏览 0 评论 0原文

我正在尝试在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

预谋 2024-10-02 09:19:04

编译器无法选择正确的方法,因为您的模型是动态。将调用更改为:

<% Html.RenderPartial("ProjectName", (int)(Model.Id)); %>

或 Id 的任何其他数据类型。

The compiler cannot choose the correct method because your Model is dynamic. Change the call to:

<% Html.RenderPartial("ProjectName", (int)(Model.Id)); %>

Or any other datatype Id is.

逆夏时光 2024-10-02 09:19:04

如果其他人犯了与我相同的错误:

@Model MyViewModel

这会将您的模型视为动态

@model MyViewModel

这是一个正确的强类型视图。注意大小写的缺失!

请注意,这是 Razor,与原来的问题不同。

In case anyone else made the same mistake I did:

@Model MyViewModel

This will treat your model as dynamic

@model MyViewModel

This is a correctly strongly typed view. Note the lack of capitalisation!

Note, that this is Razor, unlike the original question.

摘星┃星的人 2024-10-02 09:19:04

我发现通过的唯一方法,例如。 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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文