简体   繁体   中英

ASP.net MVC Tempdata getting DataSet's values out of it

Hey all I am new to the MVC world and was wanting to get a few values from the TempData that I made that houses 3 DataSet's inside it.

The values that are inside the TempData are these:

在此处输入图片说明

then selecting tTrip then rows then Results View:

在此处输入图片说明

finally seeing the DataSet values for tTrip:

在此处输入图片说明

I populate the TempData like so (simplify):

allData.Merge("tEvents"); //Gathers data and places it into tEvents
allData.Merge("tTrip"); //Gathers data and places it into tTrip
allData.Merge("tExternalTrainingMain"); //Gathers data and places it into tExternalTrainingMain

TempData["jsonData"] = allData;

I've tried:

string blah = TempData["jsonData"][0]["somename"].toString();

string blah = TempData["jsonData"][0].somename.toString();

string blah = TempData["jsonData"][0][0].somename.toString();

string blah = TempData["jsonData"][0][0][0].toString();

But only get errors. What is the proper way of getting the dataset values out of the TempData array?

UPDATE for DavidG

在此处输入图片说明

在此处输入图片说明

The indexed property that gives you the value from TempData returns a object of type object . You need to cast your value to the desired type. For example:

var myDataSet = TempData["jsonData"] as DataSet;
if(myDataSet != null)
{
    We have a dataset now!
    string blah = myDataSet.Tables[0]["somename"].toString();
}

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