jquery - JavaScript runtime error: Unable to get property 'domain_name' of undefined or null reference -
i'm getting popup undefined , showing error below:
unable property 'domain_name' of undefined or null reference.
can body on this
from view:
@html.actionlink("details", "", new { id = item.id }, new { onclick = "somefunction(" + item.id + ")", href = "javascript:void(0)" }) javascript
function somefunction(id) { $.ajax({ type: 'post', url: '@url.content("~/")contracts/test/', data: { 'id': id }, datatype: 'json', success: function (data) { alert(data.domain_name); }, error: function (xhr, status, exception) { alert("error: " + exception + ", status: " + status); } }); } controller action
enter code here public jsonresult test(int id) { var result = (from cntrct in db.contracts cntrct.id == id select new { cntrct.domain_name, cntrct.id}).toarray(); return json(result); } below data i"m getting db can't pass javascript back. 
error 
script7002: xmlhttprequest: network error 0x2ef3, not complete operation due error 00002ef3. contracts
can try in json action method
action
public jsonresult test(int id) { var result = (from cntrct in db.contracts cntrct.id == id select new { cntrct.domain_name, cntrct.id, cntrct......}).toarray(); return json(result); } script
function somefunction(id) { $.ajax({ type: 'post', url: '@url.content("~/")contracts/test/', data: { 'id': id }, datatype: 'json', success: function (data) { alert(data.domain_name); } }); }
Comments
Post a Comment