views:

87

answers:

2

I have a form where users can enter data that ultimately would be used to create new Customer, CreditCard, and Membership objects. I want to add recaptcha to the page. This does it's validation on the server side. All other verification will be done client side with javascript with perhaps an extra layer of validation on the server side.

Should the captcha fail, I want to redirect the user back to the form and reenter their information automatically, and do some pretty jquery to highlight the invalid field.

I'm looking for the best practice to do this. Should I create some sort of display object that has a Customer obj property, a CreditCard obj property, and a Membership obj property, or should I just pass the MVC FormCollection object back to the page and use it to populate the form?

While the custom display object would be more work, I plan on using ViewData to store a reference to the field that failed validation. Therefore the custom display object would not require me to use the ViewData dictionary, which I like to avoid.

What are your thoughts on what I should do, weighing best practices as a factor?

+1  A: 

I think working with strongly-typed objects is better then just using the FormCollection. I suggest you create a ViewNodel object that will have all the property's you need in the view, and work with a strongly-typed view too.

ASP.NET MVC Partial Views and Strongly Typed Custom ViewModels

CD
+1  A: 

As CD mentioned above, a ViewModel that wraps (and conditionally exposes or augments, as needed) the objects you're working with on a page is fine for display, just be a bit more selective in what you post back.

As far as error handling goes, you'll probably want to look into using ModelState as a generic way to cleanly deal with and present them.

48klocs