My x.js file :-
function showSfgf(Id) {
$(document).trigger("onPageChange", '/v.mvc/Update?Id=' + Id);
}
My controller class :-
public ActionResult Update(int Id)
{
ViewBag.Id = Id;
return PartialView("Update");
}
My y.js file :-
$("#renderView").load("/v.mvc/View", function () {
getDetails(ViewBag.Id, populateData);
});
What am I trying to do is ,passing a value from x.js and then trying to receive it in y.js . So i red ViewBag is one option to do this. but in I am getting ViewBag.Id is undefined . what did i missed here ?
If you want to access razor keyword like ViewBag in your script section of your cshtml file, add this symbol:
@
Like:
$("#renderView").load("/v.mvc/View", function () {
getDetails(@ViewBag.Id, populateData);
});
Now if you are passing string on your first parameter on your getDetails function, use proper single quote:
$("#renderView").load("/v.mvc/View", function () {
getDetails('@ViewBag.Id', populateData);
});