Being a newbie in asp and jquery, I have a question regarding how data is updated from the controller to the view. In my controller I change the value of a boolean to true; update the model and return to the partial view.
obj.LastApproval = true;
----
ModelState.Clear();
return PartialView("_Approval", obj);
I would like to use that boolean to trigger a different message on the Ajax callback.
if I do this, the value is not updated and the @Model.LastApproval is still false
function ApprovalComplete() {
if ('@Model.LastApproval' === "True") {
$.notify({
// options
icon: "ti-save",
message: "The Approval process is now complete. Emails have been sent to Task owners."
}, {
// settings
type: 'success',
delay: 3000,
});
}
};
But If I do this dirty trick... by adding a hidden input in the form
<input id="lastapproval" asp-for="LastApproval" type="text" hidden />
and then use the value of that input in the callback function it does work...
function ApprovalComplete() {
var last = $('#lastapproval').val();
if (last === "True") {
$.notify({
// options
icon: "ti-save",
message: "The Approval process is now complete. Emails have been sent to Task owners."
}, {
// settings
type: 'success',
delay: 3000,
});
}
};
I would like to understand why? thank you.
CodePudding user response:
why because razor and whole asp.net is server side rendering have a look on this answer might help to achieve your requirement