Ich habe eine Seite mit einer Ajax-Form darauf. Wenn ich das Submit drücke, sollte es ein Lade Gif laden. Siehe das folgende HTML und javascript:asp.net MVC Form Validierung in Javascript
@ using (Ajax.BeginForm ("ActionName", "ControllerName", null, neue AjaxOptions {HttpMethod = "POST", UpdateTargetId = "DivToUpdate"}, neue {ID = "myForm "})) { @ Html.AntiForgeryToken();
@Html.LabelFor(model => model.PagerSize)
@Html.EditorFor(model => model.PagerSize, new { htmlAttributes = new { @class = "form-control myForm", style = "width:100px" } })
@Html.ValidationMessageFor(model => model.PagerSize)
<input id = "ajaxFormSubmitButton" type = "submit" />
}
<script>
$("#myForm").submit(function (event) {
DisplayLoading();
});
</script>
Es funktioniert gut, bis mein Modell nicht gültig ist. Zum Beispiel, wenn ich eine Pagergröße außerhalb meines Bereichs habe, wird mein Lade-GIF angezeigt, da die Seite nichts anderes lädt. Ist es möglich, das DisplayLoading nur bei ModelState.IsValid zu laden? so etwas wie diese
Zum Beispiel:
<script>
$("#myForm").submit(function (event) {
If (MyMagicVariableWhichKnowsMyModelStateIsValid){
DisplayLoading();
}
});
</script>
Pls Format, um die Frage – User3250