Note that there are some explanatory texts on larger screens.

plurals
  1. POAppending each data using jquery from IList<> filled with linq data using ViewData MVC 3
    text
    copied!<p>I'm trying to extract data from my generic list filled with linq data using ViewData and posting retrieved data in View using jquery .append, Example:</p> <p><strong>View</strong></p> <pre><code>@{ IList&lt;ProjectName.Models.Employees&gt; deserialize = ViewData["Employees"] as List&lt;ProjectName.Models.Employees&gt;; } &lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;Index&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;script src="../../Scripts/jquery-1.7.1.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; $(function () { $('#ViewData').click(function () { $("#employee").append("&lt;tr&gt;&lt;td&gt;" + "@deserialize[1].FirstName.ToString()" + " &lt;/td&gt;&lt;/tr&gt;"); }); }); &lt;/script&gt; &lt;div&gt; &lt;button id="ViewData"&gt;View Data&lt;/button&gt; &lt;table id="employee"&gt; &lt;/table&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p><strong>Controller</strong></p> <pre><code>Public ActionResult Index() { var empList = new List&lt;ProjectName.Models.Employees&gt;(); var emps = from emp in _employees.Employees select new Models.Employees { FirstName = emp.FirstName, LastName = emp.LastName, Title = emp.Title }; ViewData["Employees"] = emps.ToList(); return View(emps); } </code></pre> <p><strong>Model</strong></p> <pre><code>Public class Employees { public string FirstName { get; set; } public string LastName { get; set; } public string Title { get; set; } } </code></pre> <p><strong>Question</strong></p> <p>How can I get each record or users with the properties(FirstName, LastName, and Title) and append each retrieved value on a table in View using jquery</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