How can I validate nested model?

Dvir

Problem:
I trying to validate the nested Model but the data annotation attribute is not executing when the Nested Model Instance create.

public class Model
{
    [Required]
    string MainTitle {get;set;}

    public NestedModel NestedModel { get; set; }
}
public class NestedModel
{
    [Required]
    string SubTitle {get;set;}
}

At The Controller:

public ActionResult GetTitles(Model model)
{
    if(ModelState.IsValid)
    {
       //Submodel is always valid even if the sub-title is null.
    }
}

Doesn't Mvc4 Support it? How can I extend the validation to work with this aspect?

JoeTac

I had the same problem. I ended doing this:

public ActionResult GetTitles(Model model)
{
    if(ModelState.IsValid && TryValidateModel(model.NestedModel, "NestedModel."))
    {
       //Submodel will be validated here.
    }
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How I can validate a Django form with a model attribute?

From Dev

laravel 5.1 : how can i get nested relation from model?

From Dev

How can I populate Kendo UI grid using nested model?

From Dev

How can I populate multiple references to a model, within a nested document?

From Dev

How to validate existence of parent id in child model in Rails for nested attributes

From Dev

How to validate existence of parent id in child model in Rails for nested attributes

From Dev

Validate uniqueness nested model params

From Dev

How can I make validate with minimal one input with jquery validate?

From Dev

How can I validate the syntax of a django template?

From Dev

How can I validate UTC date

From Dev

How can I validate the image pixel?

From Dev

How can i validate email confirmation token?

From Dev

how can I validate a list index as an integer?

From Dev

How can I validate the request user in Laravel?

From Dev

How can I validate my .vimrc?

From Dev

How can i validate number of words?

From Dev

How can I validate an installation DVD?

From Dev

How can i validate and exit QInputDialog?

From Dev

How can I validate or format dates in excel

From Dev

How can I validate the email writing on UWP?

From Dev

how can I validate the language of an xcode app?

From Dev

How can I validate email address with jQuery?

From Dev

How can I validate array in laravel 5.3?

From Dev

How can i validate email in android?

From Dev

How can I validate the Path for a javafx image

From Dev

How can I validate json data in laravel?

From Dev

How can i validate jquery Regular expression?

From Dev

How can I make angular-formly deal with an unknown number of model fields that are nested in an array property

From Dev

Using nested set model to store Hierarchical data in sqlite how can I move a category into another category

Related Related

  1. 1

    How I can validate a Django form with a model attribute?

  2. 2

    laravel 5.1 : how can i get nested relation from model?

  3. 3

    How can I populate Kendo UI grid using nested model?

  4. 4

    How can I populate multiple references to a model, within a nested document?

  5. 5

    How to validate existence of parent id in child model in Rails for nested attributes

  6. 6

    How to validate existence of parent id in child model in Rails for nested attributes

  7. 7

    Validate uniqueness nested model params

  8. 8

    How can I make validate with minimal one input with jquery validate?

  9. 9

    How can I validate the syntax of a django template?

  10. 10

    How can I validate UTC date

  11. 11

    How can I validate the image pixel?

  12. 12

    How can i validate email confirmation token?

  13. 13

    how can I validate a list index as an integer?

  14. 14

    How can I validate the request user in Laravel?

  15. 15

    How can I validate my .vimrc?

  16. 16

    How can i validate number of words?

  17. 17

    How can I validate an installation DVD?

  18. 18

    How can i validate and exit QInputDialog?

  19. 19

    How can I validate or format dates in excel

  20. 20

    How can I validate the email writing on UWP?

  21. 21

    how can I validate the language of an xcode app?

  22. 22

    How can I validate email address with jQuery?

  23. 23

    How can I validate array in laravel 5.3?

  24. 24

    How can i validate email in android?

  25. 25

    How can I validate the Path for a javafx image

  26. 26

    How can I validate json data in laravel?

  27. 27

    How can i validate jquery Regular expression?

  28. 28

    How can I make angular-formly deal with an unknown number of model fields that are nested in an array property

  29. 29

    Using nested set model to store Hierarchical data in sqlite how can I move a category into another category

HotTag

Archive