Reputation: 7433
I'm designing an ASP.NET MVC 4 solution that will allow a user to import an Excel file, make specific modifications to it on the page, and export the file in the same format. I'm trying to make a View called Grid that will display the contents of a large Data Set which contains all of the data from the Excel spreadsheet.
public ActionResult Grid()
{
DataSet ds = TempData["DataSet"] as DataSet;
string exampleCell = ds.Tables[0].Rows[3][2].ToString();
return View();
}
exampleCell is an example of how I am extracting single cells from the table. I imagine I can iterate through all of the columns and rows in the Data Set and extract all of the data using this approach. How, then, can I display all of the exampleCells on a single View?
Upvotes: 0
Views: 522
Reputation: 12805
You'd be far better off creating a Model for what you're iterating over. This will allow MVC to generate the Model when your user clicks Save on the client side.
So you'll have a class that will encapsulate the values in each row. Have another Model which will have an IEnumerable/IList of your first Model you created.
In your Controller method, convert the DataSet to these models, and then pass the model with the collection to your View. Populate your HTML grid/table by iterating through the enumerable.
If you want to save all of the user's changes in one shot, wrap your grid/table in a form, and use the same Model (with the IEnumerable) as a parameter for the POST method. That will populate the entire model back for you when it calls the server again.
That might be a little unwieldy to try and figure out what changed (unless you just want to do a single mass data dump again), so if you want to save each action, that'd be just as easy to do with single client side AJAX calls.
Upvotes: 1