简体   繁体   中英

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. How to use the model binding with data sets. can any one give me a solution

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 -

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM