我是棱角分明的新手。在这里,我正在做简单的演示项目。我刚刚放了名字字段,我正在验证使用客户端脚本,它工作正常。 但当我在html.beginform周围包装时,它只是跳过验证。 并且所有验证消息都会在项目加载时显示。 我无法理解为什么会这样。
@{
ViewBag.Title = "ValidationCheck";
}
<h2>ValidationCheck</h2>
<html>
<head>
</head>
<body>
@using(Html.BeginForm()){
<form ng-app="Myapp" name="myForm" ng-controller="MyController" ng-submit="Click()" novalidate>
<table>
<tr>
<td>
@* <input type="text" ng-model="name1" name="name" ng-minlength=3 ng-maxlength="10" required />*@
@Html.TextBox("name","", new {@ng_model="name1",@ng_minlength=3, @ng_maxlength="10",required = "required"})
</td>
<td>
<p ng-show="submitted && myForm.name.$error.minlength">Name is short</p>
<p ng-show="submitted && myForm.name.$error.maxlength">Name is Long</p>
<p ng-show="submitted && myForm.name.$error.required">Name is Required</p>
</td>
</tr>
<tr>
<td>
<input type="submit" value="submit" ng-click="submitted=true" />
</td>
</tr>
</table>
</form>}
</body>
</html>
<script>
var app = angular.module('Myapp', []);
app.controller("MyController", function ($scope, $http) {
$scope.Click = function () {
debugger;
if ($scope.myForm.name.$valid) {
alert("open");
// return true;
}
}
});
</script>