是否可以为@ Html.EditorFor添加角度验证。请参阅下面的代码。
- >这就是我从控制器获取局部视图的方法
$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>
但这有效
<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>
我想使用第一个代码,但它不起作用。