我正在使用MVC Contrib网格来渲染,排序和过滤我的数据网格,但我现在有问题,现在它已经升级为MVC3和Razor。我的列集合中的自定义方法不适用于aspx页面,并且Action列方法现在已过时。如何获得MVC的贡献网格自定义列表使用aspx
我用网格操作方法来呈现MVC 2我的专栏是这样的:
...
<% Html.Grid(Model).Columns(column => {
column.For(x => x.Id);
column.For(x => x.Name);
column.For(x => x.Email);
column.For(x => x.DateOfBirth);
column.For("View User").Named("Tools").Action(x => { %>
<td>
<%= Html.ActionLink("View", "View", new { id = p.Id })%>
<%= Html.ActionLink("Edit ", "Edit", new { id = p.Id })%>
//Snip as there are too many tools :-)
//.....
<%= Html.ActionLink("Delete", "Delete", new { id = p.Id })%>
</td>
<% });
...
现在有了最新的版本有一个自定义的方法,它取代了过时的操作方法。我研究了如何完成in here,现在基本适用于我,但是我在aspx视图(url等)中放弃了所有助手,现在需要在我的模型中使用另一种方法呈现我的内容,如下所示:
...
<% Html.Grid(Model).Columns(column => {
column.For(x => x.Id);
column.For(x => x.Name);
column.For(x => x.Email);
column.For(x => x.DateOfBirth);
//the new custom column
column.Custom(Model.ToolsRenderer);
<% });
...
以下称为ToolsRenderer的网格模型方法用于呈现我的html字符串。
public UserManagementViewModel : BaseModel {
//..snip
//
public object ToolsRenderer(Client client)
{
List<string> links = new List<string>();
var editLink = new TagBuilder("a");
// here is my biggest problem, before Html.ActionLink used to make
// sure that I don't have any missing links or help me if i need to
// refactor an action/controller name :-(
editLink.Attributes["href"] = GetEditUserLink(client, HttpContext.Current.Request.Url.AbsoluteUri);
editLink.SetInnerText("edit");
links.Add(editLink.ToString());
...
...lots of links to be generated here
...
return MvcHtmlString.Create(string.join(" |", links))
}
//..snip
}
这工作现在,但有没有办法让我的aspx页面像下面的剃须刀视图工作?
@Html.Grid(Model).Columns(column =>
{
column.For(x => x.Id).
column.For(x => x.Name);
column.Custom(@<td><a href='@Html.Actionlink("edit","user",new {id})' alt="@item.email"/><a></td>)
})
我想说的是这样的:
...
column.Custom(%><td><a href='<%=Html.Actionlink("edit","user",new {id})%>' alt="<%=item.email%>"/><a></td><%)
...