Coffeehouse Thread

4 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

Looking for input about web form.

Back to Forum: Coffeehouse
  • User profile image
    magicalclick

    Hello,

    I am looking for input about web form validations. I have being working on my website and the web form validation is quite painful. There are WebMatrix security, missing input, input in wrong format. And then, I have to convert the string to appropriate data type. And there have to be display when validation failed.

    That's quite a lot of code and it gets messy.

    How does people normally clean up this mess? I am thinking of making a helper class to do all that. Or there are other better approach?

    Thank you.

    Leaving WM on 5/2018 if no apps, no dedicated billboards where I drive, no Store name.
    Last modified
  • User profile image
    vesuvius

    I use MVC in Webforms and MVVM with IErrorDataInfo in client applications or the Validation Application Block in Enterprise Library

  • User profile image
    blowdart

    @magicalclick:I tend to use validation attributes for the simple stuff (required, regex etc.)

    The more complex stuff, where it may depend on current user, or a database lookup, goes into a service layer, which returns error information which can then get appended to the model state, so the errors appear on the page easily.

  • User profile image
    magicalclick

    @vesuviusMadblowdart:

    thank you guys. I don't use MVC, so, Validation Application Block is more suitable. But, seem like it is much low level than I am thinking of. I will create a simple validation class for myself instead.

    [update]

    I managed to build a validator using webmatrix. It is a class .cshtml file with @functions{}. This is how I am exposed to Request to get the form data and have build-in webmatrix security check (like disable cross-site scripting). It is a vary simple class that will replace my variable declaration. It will first define the rules. Then, grad data. Then get the data back with appropriate datatype. Still coding it. But, I have a clear picture of what to do. Smiley

    Thanks for the input.

    Leaving WM on 5/2018 if no apps, no dedicated billboards where I drive, no Store name.
    Last modified

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.