Where do you do your validation? model, controller or view

后端 未结 10 877
生来不讨喜
生来不讨喜 2020-12-25 07:52

Where do you put user input validation in a web form application?

  1. View: JavaScript client side
  2. Controller: Server side language (C#...)
  3. Model
10条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-25 08:47

    I only do it in the View and Controller, the database enforces some of that by your data types and whatnot, but I'd rather it not get that far without me catching an error.

    You pretty much answered your own question though, the important thing to know is that you can never trust the view, although that's the easiest route to give feedback to the user, so you need to sanitize on at least one more level.

提交回复
热议问题