I have been looking for a pretty basic way of automating creation of Html Forms from C#. There’s ofcourse the MVC-way with scaffolding. But I’m not happy with that. I want to easily create my html tag setup in code and add / edit the fields and validation rules in a DRY way. If someone knows of an existing project of this kind, please let me know.
EDIT : HtmlFormsHelper has evolved into “DynaForms” (repo at GitHub), I will be blogging about it soon.
(A complete rewrite of this approach I made before.)
Also read the followup CRUD sample together with NancyFx and SisoDb.
So I wrote a ~300 Loc’s helper class with which this code is all that is necessary to create basic form which maps to a poco:
Here’s a demo
Here’s the full source
Mind it’s still an early version and it’s far away from perfect, I publish it as I hope I can get comments, ideas and collaboration if someone is up to it. It’s easy to create a Gist fork and publish your own version of this little thing.
In my previous version I used FluentValidation for the server side validation, it’s still easy to use that instead of my simple validation code, but I missed a nice way to sync the FluentValidation validation rules with client side rules.