【发布时间】:2014-09-20 09:39:18
【问题描述】:
我编写了一个 C# MVC 5 Internet 应用程序,并且对 View 中的 ActionLink 有疑问。
我有以下代码:
<td>
@Html.DisplayFor(modelItem => item.mapLocations.Count)
</td>
是否可以为上面显示的值创建ActionLink?
提前致谢
编辑
我已经尝试了以下代码:
@Html.ActionLink(item.mapLocations.Count, "Index", "MapLocation", new { mapCompanyid = item.Id }, null)
我收到如下编译错误:
Compiler Error Message: CS1928: 'System.Web.Mvc.HtmlHelper<CanFindLocation.ViewModels.MapCompaniesViewModel>' does not contain a definition for 'ActionLink' and the best extension method overload 'System.Web.Mvc.Html.LinkExtensions.ActionLink(System.Web.Mvc.HtmlHelper, string, string, string, object, object)' has some invalid arguments
EDIT2
是否需要 DisplayFor 代码来显示 ActionLink 中的值?
可能是这样的:
@Html.ActionLink(Html.DisplayFor(modelItem => item.mapLocations.Count), "Index", "MapLocation", new { mapCompanyid = item.Id }, null)
【问题讨论】:
标签: c# asp.net-mvc-5 actionlink html.actionlink displayfor