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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Jignesh TrivediRank #16 · 50.3K reputationPosted Jun 12, 2012, 7:46 PM EDT
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 ChavhanRank #1,132 · 1.6K reputationPosted Jun 12, 2012, 8:53 PM EDT
Dinkar ChavhanRank #1,132 · 1.6K reputationPosted Jun 12, 2012, 8:54 PM EDT
Jignesh TrivediRank #16 · 50.3K reputationPosted Jun 12, 2012, 9:01 PM EDT
Can please share format of XML file and also share which are data you want to display?
Thx.
Dinkar ChavhanRank #1,132 · 1.6K reputationPosted Jun 12, 2012, 9:49 PM EDT
i want like this selected record
Jignesh TrivediRank #16 · 50.3K reputationPosted Jun 12, 2012, 11:57 PM EDT
Can you please create new post?
Also put your xml and snap as attachment.
thx.
Dinkar ChavhanRank #1,132 · 1.6K reputationPosted Jun 13, 2012, 2:14 AM EDT
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 TrivediRank #16 · 50.3K reputationPosted Jun 13, 2012, 4:04 AM EDT
Yes you can..
<% foreach(System.Data.DataRow row in Model.Rows) { %>
<% foreach (var cell in row.ItemArray) {%>
<%} %>
<%} %>
Dinkar ChavhanRank #1,132 · 1.6K reputationPosted Jun 13, 2012, 8:26 PM EDT