我想将整个WebGrid发送到控制器并将其转换为DataTable。
var grid1 = new WebGrid(Model.dsvm as IEnumerable<ASP_Upload_Version_1.Models.Share_Template>, canPage: true, canSort: false);
@grid1.GetHtml(tableStyle: "table table-sm table-striped table-condensed",
htmlAttributes: new { @id = "GridPractice", @class = "table table-sm table-striped-left table-bordered table-condensed", @style = "width:100%" },
columns: grid1.Columns(
grid1.Column("PracticeArea", "Practice Area"),
grid1.Column("MarketArea", "Market Area"),
grid1.Column(format: @<text>
<a data-title="Are you sure to deactivate this Input?" class="Delete"><i class="fa fa-trash" style="color:red"></i></a></text>, header: "Remove")));
因此,我可以将数据表作为用户定义的类型参数发送到SQL过程。
将WebGrid转换为JSON是否是一种好方法? 有没有更简单的选择?
答案 0 :(得分:0)
我使用
将网格转换为jsonvar _griddata = gridTojson("GridPractice");
并将其传递给控制器。在那边,我使用
将其转换为字典Dictionary<string, string[]> log = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, string[]>>(GridData);
然后我使用以下代码将数据移至DataTable
DataTable PracticeTable= new DataTable();
PracticeTable.Columns.Add("TestColumn1");
PracticeTable.Columns.Add("");
for (int i = 0; i < log.Count; i++)
{
PracticeTable.Rows.Add(log["" + i + ""][0], log["" + i + ""][1]);
}