MvcContrib 网格模型:是否可以在 GridModel 中执行 ActionSyntax我读过这篇文章,它非常有用,但我无法应用它。我不知道在最新的 MVCContrib 中,他们是否删除了“.Action()”,因为不知何故我无法访问它。

有什么办法可以将编辑链接的 ActionLink 放入网格模型中吗?

谢谢

有帮助吗?

解决方案

看来旧的方法已经被删除了。

现在介绍如何执行此操作:

网络

首先,通过构造函数将 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#

网格模型:

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/ (看 阿弥陀佛的评论)

其他提示

作为边注,更近的变化,.DoNotEncode()现在已经过时,所以使用.Encode(假)

首先,非常感谢 @Andrew 的回答: 阿弥陀佛的问题斯金纳的回答 确实解决了我的疑惑。无论如何,对于 ASP.NET MVC 4,我很难弄清楚为什么这在网格模型中不起作用:

Column.For(hospital => html.ActionLink("View Details", "Show", "Foo")).Encode(false);

为什么?因为我没有添加必要的 using 指令:

using System.Web.Mvc.Html;

我只使用了 Visual Studio Intellisense 建议的这个:

using System.Web.Mvc;

希望它可以帮助任何面临同样问题的人!

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top