This project is read-only.

DisplayTemplate validation for client input

Topics: Writing modules
Sep 4, 2011 at 7:43 PM


I am updating an existing content part that I wrote to include some client side validation in the DisplayTemplate.  The display template I currently have allows the client to edit some fields and submit them for saving, which I accomplished this by using Html.BeginForm and routing the submitted changes to a controller.  In the controller's action I was not doing any validation to the client, just trying to save the edits and redirecting back to the provided return URL.

I've gone through some of the backend and added the Required attributes (plus a few others) to fields I want to be validated, and in the display templates added the Html.ValidationSummary and Html.ValidationMessageFor in the places I wanted them.  The problem I am having is that right now I am redirecting to a return URL instead of returning a View with a model that contains all the validation error messages.  The part that I am not sure about is how to return a View that points to the orchard display template (\Views\DisplayTemplates\Parts\MyDisplayTemplate.cshtml) with the model I just tried to update (which has the validation error messages).

Any suggestions here would be appreciated!