locked
ASP.NET MVC Model Validation RRS feed

  • Question

  • User1201172537 posted

    Hi,

    I am trying to use model validation.

    I have done  validation for models  of a simple class where single dbml model does not need to refer to another columns in dbml table.

    But for dbml tables that needs to refer to columns in one or more other tables joined by foreign key relationship i am quite confused.

    Please help me figure it out?

    How can i implement model validation in the cases where a single dbml table needs to refer to columns in other table:

    For example in this scenario:

    I have Person table and a form to enter the Person information and this person need to belong to some country(Which refers to another dbml table which consist of the list of countries).


    How can i use model validation in this case?

    Please help,

    Thanks

    Monday, December 20, 2010 12:35 AM

Answers

  • User197322208 posted

    How can i use model validation in this case?

    I do not see any problem in validation - it is usual stuff. Maybe the problem is that any Person must have a Country  - but, if not null in the database ,you can add an "onvalidate" on Person and verify if the Country  is null or not.

    Please read also

    http://bradwilson.typepad.com/blog/2010/01/input-validation-vs-model-validation-in-aspnet-mvc.html

    for more detailed post.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, December 20, 2010 12:56 AM

All replies

  • User197322208 posted

    How can i use model validation in this case?

    I do not see any problem in validation - it is usual stuff. Maybe the problem is that any Person must have a Country  - but, if not null in the database ,you can add an "onvalidate" on Person and verify if the Country  is null or not.

    Please read also

    http://bradwilson.typepad.com/blog/2010/01/input-validation-vs-model-validation-in-aspnet-mvc.html

    for more detailed post.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, December 20, 2010 12:56 AM
  • User1201172537 posted

    Hi, ignatandrei

    It did resolve my problem.

    Thanks for the reply .

    Monday, December 20, 2010 5:06 AM