asp.net 4.5 webforms model binding : client side validation supported?

后端 未结 2 1274
不思量自难忘°
不思量自难忘° 2021-02-10 04:01

I\'m a huge fan of asp.net 4.5 webforms model binding using data annotations.

ascx:

     

        
相关标签:
2条回答
  • 2021-02-10 04:22

    Guys webforms have complete client side validation, it just needs to be specified once in the model, that's the whole point of Model Binding and DataAnnotations check these links below. In short Add the following reference to your Model class library project. using System.ComponentModel.DataAnnotations;

    Add this line to your web.config

    <add key="ValidationSettings:UnobtrusiveValidationMode" value="WebForms"/>
    

    Follow this link for details Webforms Model Validation

    And this link for Microsoft's complete documentation Microsoft documentaion

    0 讨论(0)
  • 2021-02-10 04:32

    As we have found in our ASP.NET WebForms projects, there is no overall useful reuse of the Model's validation attributes for client side validation.

    For example, a contact data model, with various properties like name, email, birthday etc... is not always used the same way. Sometimes it may have some mandatory fields, sometimes not, and even the required input data may differ at various points in the application.

    Thus, in our projects, we use both a client side validation implementation, and the model attributes.

    The general idea we apply is:

    • On the client side, we want to be as specific as possible, to avoid unnecessary postbacks and to provide the user with immediate, specific responses.
    • On the server side, we apply the model attributes plus more database and business-oriented validation rules and fail not so specifically. Plus, if required, some "inter-property" validation does take place when some fields are dependent from each other.

    For the client side, we have chosen the jQuery Validate Plugin (http://jqueryvalidation.org/).

    We even have built our own set of controls (that derive from the built-in WebControls), which render various (and even some custom) data rules.

    0 讨论(0)
提交回复
热议问题