mcintyre321 / FormFactory

MVC5, Core or standalone - Generate rich HTML5 forms from your ViewModels, or build them programatically
http://formfactoryaspmvc.azurewebsites.net/
MIT License
304 stars 102 forks source link

Validation in Dynamic Forms #85

Closed Ireisme closed 4 years ago

Ireisme commented 4 years ago

Firstly, this is a great library, it's the exact tool I needed for what I'm trying to do.

But I'm having problems getting validation to work on my dynamic form. Basically I have a list of validation errors generated from a service and I'm wondering if I can apply them to a dynamic form created from an PropertyVm[].

Looking at the Form.Property.cshtml it looks like it's calling AllValidationMessages to display the validation. And that method is relying on ModelState[modelName].Errors to get the validation.

I tried calling ModelState.AddModelError in my controller, but they do not appear to be showing up in the Form.Property view's ModelState.

Is there something here I am missing? Or a better way to accomplish this?

Ireisme commented 4 years ago

Never mind adding errors to the ModelState appears to work entirely correctly, and I was causing my own problems.

mcintyre321 commented 4 years ago

Great, glad to hear you got to the bottom of it!