5
I have the following scenario:
[HttpPost]
public PartialViewResult Create(string dados)
{
var clienteViewModel = DeserializeJson<ClienteViewModel>(dados);
if (ModelState.IsValid) { } // Não têm como validar.
...
}
I receive the json and convert to the Clienteviewmodel object, but this way it is not possible to validate with the "Modelstate.isValid" because it validates the model that is in the parameter.
I don’t want to have to send the form normally to Action and in its parameter put Clienteviewmodel instead of "string data (json)" because this causes the whole page to be loaded, and I don’t want that.
Is there any way to validate Viewmodel that way?
Oh yes, thanks. I just tested this way and it worked!
– Raphael
Complementing: the name of this resource is Binding (does not have a good name for English). The class that implements this is
DefaultModelBinder
. Your implementation is here.– Leonel Sanches da Silva