加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-mvc – 编辑GridModel中的链接(MVCContrib)

发布时间:2020-12-16 06:56:47 所属栏目:asp.Net 来源:网络整理
导读:MvcContrib GridModel : Is it possible to do ActionSyntax in a GridModel 我已经阅读了这篇文章,它非常有用,但我无法应用它.我不知道在最新的MVCContrib中,他们删除了“.Action()”,因为我无法访问它. 有没有我可以将编辑链接的ActionLink放入网格模型中
MvcContrib GridModel : Is it possible to do ActionSyntax in a GridModel
我已经阅读了这篇文章,它非常有用,但我无法应用它.我不知道在最新的MVCContrib中,他们删除了“.Action()”,因为我无法访问它.

有没有我可以将编辑链接的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)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读