The data got from Json i used to append to a table as rows.First data of the column needs to come in Link format.So i used ActionLink .But i get the following error as "The name 'Transaction_No' does not exist in the current context".
function CreateGrid(result) {
$.ajaxSetup({
cache: false
});
for (i = 0; i < result.data.length; i++) {
debugger;
var chk_row = true;
$('#tbl_RoleMenu tbody').empty().append('<tr id="tr-' + i + '"></tr>');
String Transaction_No = result.data[i].Loan.toString();
$('#tr-' + i).append('<td id="tdLoan-' + i + '"> @Html.ActionLink(Transaction_No, "Create", "Portfolio", null, new { @class = "openDialog", data_dialog_id = "emailDialog" }) </td>');
$('#tr-' + i).append('<td id="tdLoan-1' + i + '">' + result.data[i].Loan + '</td>');
}
}
You seem to be completely mixing server side code with client side javascript. Try fixing this mess:
function CreateGrid(result) {
$.ajaxSetup({
cache: false
});
for (i = 0; i < result.data.length; i++) {
debugger;
var chk_row = true;
$('#tbl_RoleMenu tbody').empty().append('<tr id="tr-' + i + '"></tr>');
var transactionNumber = result.data[i].Loan;
$('#tr-' + i).append('<td id="tdLoan-' + i + '"><a href="@Url.Action("Create", "Portfolio")" class="openDialog" data-dialog-id="emailDialog">' + transactionNumber + '</a></td>');
$('#tr-' + i).append('<td id="tdLoan-1' + i + '">' + result.data[i].Loan + '</td>');
}
}
As an alternative to this horrible mess I would recommend you create this markup on your server using a partial view. I guess that you are calling this function after performing an AJAX request to a controller action (that currently returns a JsonResult
). Modify this controller action so that instead of returning a JsonResult returns a PartialView and then simply inject this new markup into your DOM.