Reputation: 12294
During AJAX call is it possible to return ViewData, TempData or a session back to the view? does these variables are included in the cycle? please comment
function submitForm(frm) {
var tdata = $(frm).serialize();
$.ajax({
url: "/Organization/EditOrganizationMeta",
data: tdata,
success: function (result) {
if (result["ErrorMessage"] == "No Error") {
$("#" + result["DivName"] + "1").hide();
$("#" + result["DivName"]).show();
$("#" + result["DivName"]).empty();
$("#" + result["name"]).attr("value", result["SavedValue"]);
$("#" + result["DivName"]).append("<b>" + result["SavedValue"] + "</b>");
$("#" + result["DivName"] + "2").empty();
$("#" + result["DivName"] + "2").append("<b>Record is successfully saved</b>");
}
else if (result["ErrorMessage"] != "") {
$("#" + result["DivName"] + "1").show();
$("#" + result["DivName"]).hide();
$("#" + result["DivName"]).empty();
$("#" + result["name"]).attr("value", result["PreviousValues"]);
$("#" + result["DivName"] + "2").empty();
$("#" + result["DivName"]).append("<b>" + result["PreviousValues"] + "</b>");
$("#" + result["DivName"] + "2").append("<b>" + result["ErrorMessage"] + "</b>");
}
},
type: "POST",
datatype: "json"
});
return false;
}
Upvotes: 1
Views: 2782
Reputation: 18067
Bsaed on the JavaScript code that you just posted, I think that the best approach would be to return the parameters you want the success
function to use as JSON.
To return an object as JSON from an ASP.NET MVC controller ActionResult, you have to do the following:
return Json(myObject); //where myObject is an object that contains all the information that you want to return.
Upvotes: 1