2010-01-10 77 views

回答

4

看来,旧的方法已被删除。

这里是如何做到这一点现在:

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

1

作为一个侧面说明,最近的变化,.DoNotEncode()现已弃用,所以用.Encode(假)

0

首先,非常感谢你到@Andrew for his answerAmitabh's questionSkinner'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; 

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