asp.net mvc - Get values from controller to Javascript code -
i getting id value controller javascript code want full row value "reportssql.reportname". , want display value reportname in view through javascript.
here ,my controller
[httpget] public actionresult viewreports(int id, sqlserver_reports reportssql) { context = new cost(); //todo whole row values id, right have report id reportssql.reportname = context.sqlserverreportses.where(x => x.reportid == id).select(x=>x.reportname).firstordefault(); // list<string> report = context.sqlserverreportses.where(x => x.reportid == id).select(x=>x.reportname).tolist(); return json(reportssql.reportname, jsonrequestbehavior.allowget); }
here javascript function
function viewreport(id) { var id = id; // alert(id);// getting value gridview button , passing javascript alert var state = {}; var newurl = "/report/viewreports/"; //var newurl="@url.action("viewreports", "report")"; window.history.pushstate(state, null, newurl); $.ajax({ url: newurl + id, type: "get", success: function () { $('#viewreports').show(); $('#showgrid').hide(); document.getelementbyid('lbltipaddedcomment').innerhtml = 'report id = ' + id; // display report name here }, error: function () { bootbox.alert("error"); } }); }
like displaying value of id in label here want display vlaue of reportname in label. how reportname mean return json(reportssql.reportname, jsonrequestbehavior.allowget); in javascript function.
in success function, need use response sent server. change success function so:
success: function (reportname) { $('#viewreports').show(); $('#showgrid').hide(); document.getelementbyid('lbltipaddedcomment').innerhtml = 'report id = ' + id; // set report name $('#lblyourlabelidhere').text(reportname); }
Comments
Post a Comment