Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Feb 24, 2012 07:50 PM by jerryjoseph
Member
113 Points
318 Posts
Feb 24, 2012 07:25 PM|LINK
I'm trying to set some data in the controller and then display it in my view, but everytime I try to run it it says "Error Loading Page."
I'm using the jquery mobile plug in for this mobile site.
View:
<div data-role="listview"> <div> <div>Order Date</div> <div>Material</div> <div>Model</div> <div>Finish</div> <div>Lg (in)</div> <div>Wt (oz)</div> <div>Qty</div> </div> @foreach ( var bat in (List<Mobile_MVC.Models.PlayerHistoricalData>)ViewData["histData"]) { <div> <div>@:bat.orderDate</div> <div>@:bat.materialNum</div> <div>@:bat.modelNum</div> <div>@:bat.finish</div> <div>@:bat.length</div> <div>@:bat.weight</div> <div>@:bat.qty</div> </div> } </div>
Controller:
public ActionResult Details() { List<PlayerHistoricalData> histData = new List<PlayerHistoricalData>() { new PlayerHistoricalData() { finish = "test", weight = "test", qty = "1", orderDate = "10/10/2012", modelNum = "xxx", materialNum = "xxx", length = "123" } }; ViewData["histData"] = histData; return View(new PlayerHistoricalData()); }
Model:
public class PlayerHistoricalData { public string orderDate { get; set; } public string materialNum { get; set; } public string modelNum { get; set; } public string finish { get; set; } public string length { get; set; } public string weight { get; set; } public string qty { get; set; } public string[] batData { get; set; } }
Not sure what's going on to cause this error.
Feb 24, 2012 07:48 PM|LINK
Looks like I found out the issue was using the wrong model in my view.
Contributor
6740 Points
1257 Posts
Feb 24, 2012 07:50 PM|LINK
It can be a problem with the version of jQuery Mobile you are using. Is it an alpha version?
There are a few things I have noticed in your code.
- You do not need to use ViewData in this scenario. Avoid it when it is not needed. It uses Session under the hood.
- You dont need to write @: because @ blocks are automatically HTML encoded.
MasterV23
Member
113 Points
318 Posts
How to display data within view?
Feb 24, 2012 07:25 PM|LINK
I'm trying to set some data in the controller and then display it in my view, but everytime I try to run it it says "Error Loading Page."
I'm using the jquery mobile plug in for this mobile site.
View:
<div data-role="listview"> <div> <div>Order Date</div> <div>Material</div> <div>Model</div> <div>Finish</div> <div>Lg (in)</div> <div>Wt (oz)</div> <div>Qty</div> </div> @foreach ( var bat in (List<Mobile_MVC.Models.PlayerHistoricalData>)ViewData["histData"]) { <div> <div>@:bat.orderDate</div> <div>@:bat.materialNum</div> <div>@:bat.modelNum</div> <div>@:bat.finish</div> <div>@:bat.length</div> <div>@:bat.weight</div> <div>@:bat.qty</div> </div> } </div>Controller:
public ActionResult Details() { List<PlayerHistoricalData> histData = new List<PlayerHistoricalData>() { new PlayerHistoricalData() { finish = "test", weight = "test", qty = "1", orderDate = "10/10/2012", modelNum = "xxx", materialNum = "xxx", length = "123" } }; ViewData["histData"] = histData; return View(new PlayerHistoricalData()); }Model:
public class PlayerHistoricalData { public string orderDate { get; set; } public string materialNum { get; set; } public string modelNum { get; set; } public string finish { get; set; } public string length { get; set; } public string weight { get; set; } public string qty { get; set; } public string[] batData { get; set; } }Not sure what's going on to cause this error.
MasterV23
Member
113 Points
318 Posts
Re: How to display data within view?
Feb 24, 2012 07:48 PM|LINK
Looks like I found out the issue was using the wrong model in my view.
jerryjoseph
Contributor
6740 Points
1257 Posts
Re: How to display data within view?
Feb 24, 2012 07:50 PM|LINK
It can be a problem with the version of jQuery Mobile you are using. Is it an alpha version?
There are a few things I have noticed in your code.
- You do not need to use ViewData in this scenario. Avoid it when it is not needed. It uses Session under the hood.
- You dont need to write @: because @ blocks are automatically HTML encoded.
linkedin | twitter | www.jerryjoseph.net