[英]Using DataSet As Data Model in asp.net MVC 4 Project
I want to use Data Set as my Model in my mvc 4 project. 我想将数据集用作我的mvc 4项目中的模型。 How to use the model binding with data sets. 如何对数据集使用模型绑定。 can any one give me a solution 谁能给我解决办法
You can use DataSet Like this - 您可以像这样使用DataSet-
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 - 输出-
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.