can anyone tell How to show Datatable record (coming from xml file)in view,in that there is no Model just i am writing in controller pls
Thanks
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Jignesh TrivediPosted Jun 12, 2012, 11:46 PM
In MVC you can pass your dataobject when you retun View from Controller Action method.
For same
Make your model dymanic in aspx file.
<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage " %>
About Us
About
Put content here.
<%foreach (System.Data.DataColumn col in Model.Columns) { %>
<%} %>
<% foreach(System.Data.DataRow row in Model.Rows) { %>
<% foreach (var cell in row.ItemArray) {%>
<%} %>
<%} %>
In your Action method
public ActionResult About()
{
ViewData["Message"] = "Welcome to ASP.NET MVC!";
DataTable dt = new DataTable("MyTable");
dt.Columns.Add(new DataColumn("Id", typeof(string)));
dt.Columns.Add(new DataColumn("Name", typeof(string)));
dt.Columns.Add(new DataColumn("Discription", typeof(string)));
// you can add here logic for reading XML file and getData in Datable.
for (int i = 0; i < 3; i++)
{
int j = i + 1;
DataRow row = dt.NewRow();
row["Id"] = j;
row["Name"] = "Name_" + j;
row["Discription"] = "Discription_" + j;
dt.Rows.Add(row);
}
return View(dt);
}
hope this will help you.
Dinkar ChavhanPosted Jun 14, 2012, 12:26 AM
Jignesh TrivediPosted Jun 13, 2012, 8:04 AM
Yes you can..
<% foreach(System.Data.DataRow row in Model.Rows) { %>
<% foreach (var cell in row.ItemArray) {%>
<%} %>
<%} %>
Dinkar ChavhanPosted Jun 13, 2012, 6:14 AM
just tell me here col.caption or cell.tostring() can i write particular columns name those i want
<%foreach (System.Data.DataColumn col in Model.Columns) { %>
<%} %>
<% foreach(System.Data.DataRow row in Model.Rows) { %>
<% foreach (var cell in row.ItemArray) {%>
<%} %>
<%} %>
Jignesh TrivediPosted Jun 13, 2012, 3:57 AM
Can you please create new post?
Also put your xml and snap as attachment.
thx.
Dinkar ChavhanPosted Jun 13, 2012, 1:49 AM
i want like this selected record
Jignesh TrivediPosted Jun 13, 2012, 1:01 AM
Can please share format of XML file and also share which are data you want to display?
Thx.
Dinkar ChavhanPosted Jun 13, 2012, 12:54 AM
Dinkar ChavhanPosted Jun 13, 2012, 12:53 AM