Note that there are some explanatory texts on larger screens.

plurals
  1. POError when passing Model object to my view
    text
    copied!<p>I have created the following model object:-</p> <pre><code>namespace MvcApplication1.Models { public class listofpack { public string packageName { get; set; } public string packageId { get; set; } } } </code></pre> <p>Which i am populating its value on the controller as follow:-</p> <pre><code>public ActionResult Index() { ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application."; using (var client = new WebClient()) { var query = HttpUtility.ParseQueryString(string.Empty); query["j_username"] = "kermit"; query["hash"] = "9449B5ABCFA9AFDA36B801351ED3DF66"; query["loginAs"] = "admin"; query["loginAs"] = User.Identity.Name; var url = new UriBuilder("http://localhost:8080/jw/web/json/workflow/package/list"); url.Query = query.ToString(); string json = client.DownloadString(url.ToString()); var model = new JavaScriptSerializer().Deserialize&lt;listofpack&gt;(json); return View(model); // return Content(json, "application/json"); } } </code></pre> <p>After that on the view i am trying to loop through the model as follow:-</p> <pre><code>@model IEnumerable&lt;MvcApplication1.Models.listofpack&gt; @{ ViewBag.Title = "Home Page"; } @foreach(var item in Model) { @Html.ActionLink(item.packageId.ToString(), "about", "Home", new { id = "crm"},null) } </code></pre> <p>but when i run the view i will get the following error:-</p> <pre><code>The model item passed into the dictionary is of type 'MvcApplication1.Models.listofpack', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable`1[MvcApplication1.Models.listofpack]'. </code></pre> <p>BR</p> <p><strong>:::UPDATE:::: -----------------------------------------------------------------------------------------------------------------------------------------------------------------</strong></p> <p>i have updated the controller code to be:-</p> <pre><code>public ActionResult Index() { ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application."; using (var client = new WebClient()) { var query = HttpUtility.ParseQueryString(string.Empty); query["j_username"] = "kermit"; query["hash"] = "9449B5ABCFA9AFDA36B801351ED3DF66"; query["loginAs"] = "admin"; query["loginAs"] = User.Identity.Name; var url = new UriBuilder("http://localhost:8080/jw/web/json/workflow/package/list"); url.Query = query.ToString(); string json = client.DownloadString(url.ToString()); var model = new JavaScriptSerializer().Deserialize &lt;List&lt;listofpack&gt;&gt;(json); return View(model); } } </code></pre> <p>and on the view:-</p> <pre><code>@model List&lt;MvcApplication1.Models.listofpack&gt; @Model.Count(); @foreach(var item in Model) { @Html.ActionLink(item.packageId.ToString(), "about", "Home", new { id = "crm"},null) } </code></pre> <p>But the problem is that nothing will be displayed in the view and the <code>.count()</code> will return zero although there should be 5 jason objects passed to the view. So what might be going wrong?? Best Regards</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload