MvcContrib GridModel : Is it possible to do ActionSyntax in a GridModel 我读过这篇文章,它是相当有用的,但我不能应用这个。我不知道是否在最新的MVCContrib中,他们删除了“.Action()”,因为我无法访问它。编辑链接GridModel(MVCContrib)
有没有办法将编辑链接的ActionLink放入网格模型中?
谢谢
MvcContrib GridModel : Is it possible to do ActionSyntax in a GridModel 我读过这篇文章,它是相当有用的,但我不能应用这个。我不知道是否在最新的MVCContrib中,他们删除了“.Action()”,因为我无法访问它。编辑链接GridModel(MVCContrib)
有没有办法将编辑链接的ActionLink放入网格模型中?
谢谢
看来,旧的方法已被删除。
这里是如何做到这一点现在:
VB.NET
首先,你通过HTML对象到gridmodel类通过构造函数,那么你可以从gridmodel类中使用它。
Imports MvcContrib.UI.Grid
Public Class PersonGridModel
Inherits GridModel(Of Person)
Public Sub New(ByVal html as HtmlHelper)
Column.For(Function(u) html.ActionLink("Edit", "Edit", "Person", New With {.id = u.PersonId}, Nothing)).DoNotEncode()
End Sub
End Class
然后,在你看来,你通过它通过构造函数:
<%=Html.Grid(Model).WithModel(New MemberRetentionTrackingSystem.InboundCallGridViewModel(Html))%>
C#
GridModel:
public class PersonGridModel : GridModel {
public PersonGridModel(HtmlHelper html) {
Column.For(u => html.ActionLink(“Edit”, “Edit”, “Person”)).DoNotEncode();
}
}
查看:
< %= Html.Grid(ViewData.Model).WithModel(new PersonGridModel(Html)) %>
参考:http://www.jeremyskinner.co.uk/2009/02/22/rewriting-the-mvccontrib-grid-part-2-new-syntax/(见comment from Amitabh)
作为一个侧面说明,最近的变化,.DoNotEncode()现已弃用,所以用.Encode(假)
首先,非常感谢你到@Andrew for his answer:Amitabh's question和Skinner's answer真的解决了我的疑问。无论如何,ASP.NET MVC 4中,我很难弄清楚为什么Grid模型中的这种行为不起作用:
Column.For(hospital => html.ActionLink("View Details", "Show", "Foo")).Encode(false);
为什么?因为我不是添加必要的使用指令:
using System.Web.Mvc.Html;
我只使用这个建议由Visual Studio智能感知:
using System.Web.Mvc;
希望它可以帮助任何人面临同样的问题!