Pergunta

This is my setup:

Model => View1 => Validate Model

Model => View2 => I need to ignore Validation and just pass the Model

ViewData from Model => View3

As you can see, I'm trying to pass my Model from View to View. However, it's causing my problems because when View2 is posted, the Model wants to Validate but the form elements from View1 no longer exist in View2.

Is there a way to tell the controller not to Validate the Model that second time?

Foi útil?

Solução

I believe ValidateInputAttribute will skip validation (this will also allow people to post mark-up, which can be used for XSS attacks, so be careful). This will skip all validation for that action.

If there are only some properties that should be validated on one action method, and a different set of properties that should be validated on another action method, then you might have problem, but in that scenario, I would suggest having two different view models.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top