I have a model in my project that contains appropriate code for fetching data from my database and it stores the data in DataTable object.
In the controller, I've extracted the data from DataTable in an array of string as follows
Controller:
DataTable infotable = new DataTable();
infotable = pfd.getProfileData(userid); //getProfileData is my method in model class
foreach (DataRow row in infotable.Rows) {
studentinfo[0] = row["studentId"].ToString();
studentinfo[1] = row["firstName"].ToString();
studentinfo[2] = row["lastName"].ToString();
studentinfo[3] = row["password"].ToString();
studentinfo[4] = row["email"].ToString();
studentinfo[5] = row["contactNo"].ToString();
studentinfo[6] = (Convert.ToDateTime(row["regDate"])).ToShortDateString();
}
ViewData["studentinfo"] = studentinfo;
return View();
In the view the code that I've used to display the data is ViewBag goes like:
@foreach (string info in ViewData["studentinfo"] as string[])
{
<p>@info</p>
}
This set of code works perfectly fine and shows the required output.
Now I want the data in the ViewBag back in an array of String.
Or possibly I can pass the String itself to the view from controller, if so how can I access the passed string array in View?