Ich habe eine Situation, wenn ich versuche zu überprüfen, ob ein Formular gültig ist, aber form.valid() gibt immer true zurück. Aber wenn ich versuche, die einzelne Steuerung zu validieren, gibt es false zurück.
Dies ist mein Formular:
@using (Html.BeginForm("", "", FormMethod.Post, new { id = "tagsform" }))
{
@Html.ValidationMessageFor(x => x.EditTagsText)
@Html.TextBoxFor(p => p.EditTagsText, new
{
@id = "txtprofileedittags"
})
}
Dies ist mein ViewModel:
[Required(AllowEmptyStrings = false, ErrorMessage = "Bitte geben Sie mindestens ein Tag ein ")]
public string EditTagsText { get; set; }
Dies ist der jQuery-Code:
$('#tagsform').removeData("validator");
$('#tagsform').removeData("unobtrusiveValidation");
$.validator.unobtrusive.parse('#tagsform');
$('#tagsform').validate();
Und bei einem Klick auf die Schaltfläche "Speichern":
var isValid = $('#tagsform').validate().element($('#txtprofileedittags')); <-- false
$('#tagsform').valid() true <--
Ich möchte auch, dass form.valid() false zurückgibt, was mache ich falsch?