Note that there are some explanatory texts on larger screens.

plurals
  1. POSending Json data to @Html.Actionlink() in Jquery in MVC4
    primarykey
    data
    text
    <p>I'm binding html table with json data with the help of jquery. And I've successful done that. Also want to bind actionlink through jquery into the table with passing an Id coming from Json Data. But getting error.</p> <p>I've searched for it also gone through this article <a href="https://stackoverflow.com/questions/5830143/embed-html-actionlink-in-javascript-in-razor">Embed Html.ActionLink in Javascript in Razor</a></p> <p>The answer in this article is working if I pass static Id to the actionlink. But gives error for id coming from Json data.</p> <p>below is my code.</p> <pre><code>@{ ViewBag.Title = "DeviceManagement"; } &lt;div class="acc-container" style="width:950px;"&gt; &lt;fieldset&gt; &lt;br /&gt; &lt;div class="container_12_840"&gt; &lt;div class="grid_2" style="width: 230px;"&gt;Device Registered To&lt;/div&gt; &lt;div class="grid_3"&gt; @Html.DropDownListFor(model =&gt; model.PersonId, Model.DeviceOwner, "-- Select Owner --", new { id = "OwnerDrp" }) &lt;/div&gt; &lt;div class="linebreak"&gt;&lt;/div&gt; &lt;br /&gt; &lt;div style="clear: both;"&gt; &lt;div id="search-form"&gt; &lt;table cellpadding="0" cellspacing="0" width="100%" id="table111"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;th&gt;Device Number&lt;/th&gt; &lt;th&gt;Serial Number&lt;/th&gt; &lt;th&gt;Type&lt;/th&gt; &lt;th&gt;Owner&lt;/th&gt; &lt;th&gt;Active&lt;/th&gt; &lt;th&gt;Created&lt;/th&gt; &lt;th&gt;Actions&lt;/th&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="rowspace"&gt;&lt;/div&gt; &lt;/div&gt; &lt;/fieldset&gt; &lt;/div&gt; &lt;script&gt; $(document).ready(function () { $('#OwnerDrp').change(function () { var id = $(this).val(); $.getJSON("/Device/GetModuelOwnerDevice", { Id: id }, function (data) { $.each(data, function (i, obj) { // this will work with static id var setting = '@Html.ActionLink("Settings", "DeviceSetting", new { id = 1})'; // this will not work and give error saying "obj" not in scope var setting = '@Html.ActionLink("Settings", "DeviceSetting", new { id = obj.DeviceInfoId})'; var html = "&lt;tr&gt;&lt;td style='text-align: center;'&gt;" + obj.DeviceNumber + "&lt;/td&gt;"; html += "&lt;td style='text-align: center;'&gt;" + obj.SerialNumber + "&lt;/td&gt;"; html += "&lt;td style='text-align: center;'&gt;" + obj.Name + "&lt;/td&gt;"; html += "&lt;td style='text-align: center;'&gt;" + obj.FirstName + "&lt;/td&gt;"; html += "&lt;td style='text-align: center;'&gt;" + obj.Active + "&lt;/td&gt;"; html += "&lt;td style='text-align: center;'&gt;" + obj.DateCreated + "&lt;/td&gt;"; html += "&lt;td style='text-align: center;'&gt;" + setting + "&lt;/td&gt;"; $("#table111 tr:last").after(html); }); }); }); }); &lt;/script&gt; </code></pre> <p>Help will be appreciated.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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