I would move your form into a partial view, strongly typed to your SupplierRegisterModel eg
@inherits UmbracoViewPage<SupplierRegisterModel>
and then in your Macro Partial, I would use Html.RenderPartial to display this form passing in a new instance of the model
@{ Html.RenderPartial("~/Views/Partials/registersupplier.cshtml", new SupplierRegisterModel()); }
Now in your surface controller when there is a modelstate error you can return CurrentUmbracoPage as this keeps the ModelState intact and displays the validation errors! (whereas RedirectToCurrentUmbracoPage wipes your modelstate and validation errors.
How to return validation errors from RegisterMember partial macro?
I have a page with a partial macro RegisterModel and simple action to register new user. Basically based on this articles:
https://24days.in/umbraco-cms/2015/extending-membership/ https://24days.in/umbraco-cms/2014/dealing-with-members/
I want to return validation errors from
ModelStateto the page/ macro if user exists or any other validation or status error is returned.How do I do it?
This:
cannot be done as the macro is embedded in a page.
This:
will render just the partial content without the layout.
In addition partial cannot be strongly typed so I have no means to return the model into the partial to display
ModelStateerrors.With:
I can just reload the page with
TempData.I have no idea how to return errors into the
ValidationSummary.Any ideas how this things are handled with macro partials in umbraco 7?
Hi Manila
I would move your form into a partial view, strongly typed to your SupplierRegisterModel eg
and then in your Macro Partial, I would use Html.RenderPartial to display this form passing in a new instance of the model
Now in your surface controller when there is a modelstate error you can return CurrentUmbracoPage as this keeps the ModelState intact and displays the validation errors! (whereas RedirectToCurrentUmbracoPage wipes your modelstate and validation errors.
eg
if (!ModelState.IsValid) { return CurrentUmbracoPage(); } else { TempData["success"] = true; return RedirectToCurrentUmbracoPage(); }
if that makes sense?
regards
marc
Marc, thanks. It works great!
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.