2010-01-10 78 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; 

希望它可以幫助任何人面臨同樣的問題!