Modellbindung für asp.net 4.5-Webformulare: clientseitige Validierung unterstützt?
Ich bin ein großer Fan von asp.net 4.5 Webforms-Modellbindung mit Datenanmerkungen.
ascx:
<asp:FormView ItemType="Contact" runat="server" DefaultMode="Edit"
SelectMethod="GetContact" UpdateMethod="SaveContact">
<EditItemTemplate>
<asp:ValidationSummary runat="server" ID="valSum" />
Firstname: <asp:TextBox runat="server" ID="txtFirstname" Text='<%#: BindItem.Firstname %>' />
Lastname: <asp:TextBox runat="server" ID="txtLastname" Text='<%#: BindItem.Lastname %>' />
Email: <asp:TextBox runat="server" ID="txtEmail" Text='<%#: BindItem.Email %>' />
<asp:Button ID="Button1" runat="server" Text="Save" CommandName="Update" />
</EditItemTemplate>
</asp:FormView>
.cs:
public void SaveContact(Contact viewModel)
{
if (!Page.ModelState.IsValid)
{
return;
}
}
public Contact GetContact()
{
return new Contact();
}
Modell:
public class Contact
{
[Required]
[StringLength(10, ErrorMessage="{1} tis te lang")]
public string Firstname { get; set; }
[Required]
[StringLength(10)]
public string Lastname { get; set; }
[Required]
[EmailAddress]
public string Email { get; set; }
}
Frage:
Wird die clientseitige Validierung in Webformularen wie in MVC sofort unterstützt? Oder sollten wir uns auf Bibliotheken von Drittanbietern verlassen (DAValidation). Ist es möglich, die Güte von Html.EnableClientValidation () auf Webformulare zu portieren?
Grüße,
Bart