I want to use Data Set as my Model in my mvc 4 project. How to use the model binding with data sets. can any one give me a solution
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
You can use DataSet Like this -
Controller Action -
public ActionResult Index()
{
DataSet ds = new DataSet();
DataTable dt = new DataTable("Marks");
dt.Clear();
dt.Columns.Add("Name");
dt.Columns.Add("Marks");
DataRow dr = dt.NewRow();
dr["Name"] = "rami";
dr["Marks"] = "500";
dt.Rows.Add(dr);
ds.Tables.Add(dt);
return View(ds);
}
Index Action -
@model System.Data.DataSet
@using System.Data
@foreach (DataRow row in Model.Tables["Marks"].Rows)
{
@(row["Name"] + " " + row["Marks"])
}
Output -