Is it possible to add angular validation for @Html.EditorFor. Please see code below.
--> This is how I get the partial view from the controller
$scope.editClient = function () {
var id = 1;
$http.get('/Clients/GetClientByClientId?id=' +id)
.then(function (response) {
debugger;
var divTemplate = response.data;
var element = angular.element(document.getElementById('id_chosen_view'));
element.empty();
element.append(divTemplate);
$compile(element)($scope);
})
}
<div class="form-group">
<label for="editCompany">Company</label>
@Html.EditorFor(model => model.Company, new { htmlAttributes = new { @class = "form-control", required="required", id="editCompany" } })
<span style="color: red;" ng-show="formEditClient.Company.$touched && formEditClient.Company.$invalid">Company name is required.</span>
</div>
but this works
<label for="inputContactPerson">Contact Person</label>
<input id="inputContactPerson" type="text"
class="form-control" ng-model="editClient.ContactPerson" name="ContactPerson" required/>
<span style="color: red;" ng-show="formEditClient.ContactPerson.$touched && formEditClient.ContactPerson.$invalid">Contact Person is required.</span>
I would like to use the first code but it doesn't work.