Ng model on hidden razor inlet does not work
In my MVC 5 Razor view, I created a hidden field like:
@Html.HiddenFor(x => x.FormData.UserId,
new { ng_model = "selectedEmployee.userId" })
When I do the required angular action to populate the property selectedEmployee.userId
, the hidden input is not populated.
But, when I change it to
@Html.TextBoxFor(x => x.FormData.UserId,
new { ng_model = "selectedEmployee.userId" })
Works and data is sent to the server.
and
<input type="hidden" name="FormData.UserId" value="{{selectedEmployee.userId}}">
works but
@Html.HiddenFor(x => x.FormData.UserId,
new { value = "{{selectedEmployee.userId}}" })
not. (which is probably due to the fact that Razor is rewriting the HTML value)
What is the reason why hidden input with ng model doesn't work in Razor?
+3
source to share
2 answers
Here's how to assign a value to the Hidden Field. The sign of the value attribute 'V' must be capitalized.
<div data-ng-controller="MyFunction">
@{Html.BeginForm("SchoolMedium", "BasicSetup", FormMethod.Post, new { });
@Html.HiddenFor(s => s.SchoolMediumId, new { Value = "{{mascotmedium.SchoolMediumId}}" });
Html.EndForm();
}
and in the controller
$scope.EditWhenAdded= function(row){
$scope.mascotmedium = row.entity;
};
+1
source to share