Validation Server/Client ?

Sep 14, 2012 at 1:41 PM
Edited Sep 14, 2012 at 3:51 PM

Hi,

 

First of all, what an amazing project ! Exactly what i was looking for you just saved me loooooooot of time (probably weeks)

I analyzed your code, and I have a question about validation :

  • You use Server side validation right ? So why don't you used client side validation ? Is it due to a security issue to avoid submiting a manually corrupted form without further control ?

 

Thank you very much again !

Coordinator
Sep 14, 2012 at 7:14 PM

I honestly don't know why I did it that way. I guess it was just because MVC was very young at the time and client side validation didn't seem like the way to go for my needs.

If you would like to build some client side validation features in, I'd be glad to work with you on it.

I'm not working on this project anymore, so you're contributions are welcome.

Sep 17, 2012 at 10:43 AM
Edited Sep 17, 2012 at 10:48 AM

I'll be glad too :) Your solution is elegant and adding a client side validation will improve it for a better UX

 

I was looking at your solution and trying to use it with Razor and Asp.Net MVC4 this morning and I have an issue :

  • The RenderHtml method returns a string containing all the fields, but Razor do not intererprate it as HTML but only display the html code like if it was a string (raw data)

This is really weird...

 

EDIT : Sorry for the question if forgote that in Razor to render string to HTML use this

@MvcHtmlString.Create(@Model.RenderHtml())

Coordinator
Sep 17, 2012 at 11:31 AM

This is the project's age showing again. It was written before IHtmlString was introduced. The render methods need to be converted.

Sep 17, 2012 at 12:30 PM
Edited Sep 17, 2012 at 3:44 PM

I guess It has to be.

And I think that in the rendering methods we have to be carefull with the engine (Aspx or Razor)

I have  not yet sucessfully make your code work with MVC3 and Razor. I have an issue with the posted Form model.
Using the Demo1 method, the input fields are correctly displayed but are lost (=null) after the Post.

I think it's also due to the render method. I am investigating

Edit 1 : After investigation the problem is in MVC3/4 when you post a Model, the Parameterless constructur is called. And the Form parameterless constructor replace the fields array by an empty one. This cause the issue in submitting the form.

Edit 2 : I find the issue for Asp.Net MVC 3 or 4. The modelBinder attributes on the class Form is not triggered. So you decorate the HttpPost Action like this

 public ActionResult ActionPost([ModelBinder(typeof(DynamicFormModelBinder))] Form form)

Or insert it in the Global.asax in Application_Start()

ModelBinders.Binders[typeof (Form)] = new DynamicFormModelBinder();
Jan 9, 2013 at 3:58 AM

You can easily convert application to Razor using below syntax

 @Html.Raw(Model.RenderHtml(true))

Jan 31, 2013 at 6:47 PM
massanu wrote:
I guess It has to be. And I think that in the rendering methods we have to be carefull with the engine (Aspx or Razor) I have  not yet sucessfully make your code work with MVC3 and Razor. I have an issue with the posted Form model. Using the Demo1 method, the input fields are correctly displayed but are lost (=null) after the Post. I think it's also due to the render method. I am investigating Edit 1 : After investigation the problem is in MVC3/4 when you post a Model, the Parameterless constructur is called. And the Form parameterless constructor replace the fields array by an empty one. This cause the issue in submitting the form. Edit 2 : I find the issue for Asp.Net MVC 3 or 4. The modelBinder attributes on the class Form is not triggered. So you decorate the HttpPost Action like this public ActionResult ActionPost([ModelBinder(typeof(DynamicFormModelBinder))] Form form) Or insert it in the Global.asax in Application_Start() ModelBinders.Binders[typeof (Form)] = new DynamicFormModelBinder();
I didn't need to do any of this to get it working in Razor. I just did as pradip says and used Html.Raw()

As for validation, I am integrating Kendo into this so I can get robust HTML 5 client side validation. I am going to keep the validation code the way it is now probably just to do a second pass , server side validation check - although that may be unnecessary as it shouldn't happen and is not a security issue.

Drew