Topic: Hidden field not updating in partial view on main view rendered as ajax
I have a simple view with a partial view in it and have simple model with 2 properties. Based on boolean property I am controlling action that needs to be taken.
My main View looks like
Layout = "~/Views/Shared/_Layout.cshtml";
Partial view is like
After button is clicked it activates/deactivates record based on current Action (boolean) property, from within same action method, after user status is changed I am fetching same partial view with toggled Action property and converting into string (using Partial view to string) and returning this as json result and displays updated partial view without page refresh.
I have inspected returned string at it has proper form data (with updated Action value within hidden field) but when it is rendered in the view I just see updated text (Activate converted to Deactivate and vice versa) but hidden field value remains same which was at time of loading the main view.
My controller action method looks like
public async Task ChangeStatus(UserData model)
var result = // call API to change user status
model.Action = !model.Action;
JsonResponse response = new JsonResponse
Succeeded = result.Succeeded,
Title = result.Succeeded ? "" : "Record not updated",
AdditionalData = (await this.RenderViewToStringAsync("_UserAction", model))
And replacing current content with new partial view string like below
I want to know why this is happening as partial view to string returned is correct, also activate text is updated correctly it is just hidden field which does not get updated.
Note: if I use value property on hidden field and set that with Model.Action then it works fine but I wanna know reason behind this behaviour that why partial view hidden filed does not update at time of rendering while we have correct model.