tags:

views:

87

answers:

2

Hi all In my MVC application for booking accommodation I have the following:

  • Action to display the selected room with input-forms for extra info GET:"Details" This view has multiple forms on it, each posting to a different action.

Examples:

  • Action to update the number of guests POST:"UpdateGuests"
  • Action to select start date POST:"SelectStartDate"
  • Action to add breakfast POST:"AddBreakfast"
  • Action to delete room POST:"RemoveProductFromCart"
  • Action to proceed to next step POST:"Proceed"

Most of these actions will redirect back to the GET:"Details" view so the user can perform another action if required, in the case of the proceed, this will redirect to the next view OR if there is some reason they cannot proceed it will display the validation message as to why on the "Details" view.

I'm not sure of the best way to deal with validation, here's some options I've thought of.

  • use TempData[] to store validation messages and REDIRECT to "Details" view where we add any TempData errors so the ModelState.
  • in the POST:"xxxxxx" Action populate the ModelState and RENDER the "Details"

This is not a high volume site so TempData is an option.

Any ideas gratefully welcomed.

Edit: Additional info:

  • I'm using DataAnnotations for validation rules in some places.
  • adding Ajax as progressive enhancement is planned, but it should work without.
A: 

Have you taken a look at how nerd Dinner does validation? I've used this approach with forms that contain several Partial Views and it works great.

You can even modify to validate using jQuery on the fly if that's what you want to do.

griegs
from what I see on this page ( http://nerddinnerbook.s3.amazonaws.com/Part5.htm ) Nerd dinner seems to use a similar approach to my second option. I'm using DataAnnotations for validation, but that should not affect the principle.
Myster
A: 

I think that your second option is the best : each post actions will do the required validations, populate the ModelState with the error messages and every post will return the same view, rebuilt using your model.

Another option, a little bit harder but giving a much better user experience is to do some actions (like update number of people, select start date, add breakfast) using an ajax call. That way, you can return only the little bit of informations required by this action, refresh only that part of the screen and add some error messages if needed.

I hope it will help.

mberube.Net
adding ajax as progressive enhancement is the plan, but we have not got to that yet :-)
Myster