我有一个MVCContrib网格,它显示从Account对象中选择的属性。我希望用户选择一行并被带到另一个页面,以查看他们单击的行所代表的对象的完整属性。如何将.Selected操作添加到网格的行?
发布于 2010-06-22 02:19:47
我今天也遇到了类似的问题。
您可以像这样使用.RowAttributes:
Html.Grid(Model).Columns(column =>
{
column.For(e => e.Id);
column.For(e => e.Message);
})
.RowAttributes(x => new Dictionary<string, object>
{{"onClick", "window.location.href = 'google.com'"}})
.Render();结果,当你点击一个,它会触发javascript "onclick“并打开google。您可以通过在Lamda中使用"x“来更改url以传入Id。
发布于 2012-12-13 07:20:52
如果您在MVC3上下文中使用网格,您也可以通过服务器端的扩展类来完成此操作:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MvcContrib;
using MySolution.ViewModels;
namespace MySolution.Models.Extensions
{
public static class RowAttributeExtensions
{
public static Hash GetRowAttributes(this MySolution.ViewModels.Model)
{
string onclickFunctionBody = "{window.location.href = '/MyController/MyAction?id=" + Model.Id + "'; return false;}";
Hash hash = new Hash(onclick => onclickFunctionBody)
return hash;
}
}
}在客户端,这将采取以下形式:
@Html.Grid(Model).RowAttributes(row => row.Item.GetRowAttributes()).Columns(column =>
{
column.For(c => c.Col1);
column.For(c => c.Col2);
...
})https://stackoverflow.com/questions/2907774
复制相似问题