问题
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 -

来源:https://stackoverflow.com/questions/21451028/using-dataset-as-data-model-in-asp-net-mvc-4-project