Passing Model Back With CurrentUmbracoPage And Surface Controllers?
Using MVC, if you post to an action do whatever logic you need. And want to pass a model back, this doesn't seem possible with Umbraco MVC?
In a normal MVC app I can just go
var viewModel = new myCoolViewModel();
return View(viewModel)
But it doesn't look like you can do this with Umbraco MVC? If not, when posting a form and the validation is wrong. How to you keep the form state without being able to return a viewModel?
I too am finding this situation a little limiting, here is my fix for when you want to redirect to the current page but pass in a partial view to render and an optional model, this is an example ChangePassword Post action:
[NotChildAction] [HttpPost] public ActionResult ChangePassword(ChangePasswordViewModel model) { if (!ModelState.IsValid) return CurrentUmbracoPage();
var user = Membership.GetUser(); if (user == null) return RedirectToCurrentUmbracoPage("Membership/UserNotLoggedIn");
if (!user.ChangePassword(model.Password, model.NewPassword)) { ModelState.AddModelError("Password", "The password change failed, please ensure your current password is correctly entered"); return CurrentUmbracoPage(); }
The 2 lines at the beginning simply check for the existance of the view and model in the TempData and if found this view will render the necessary view passing in the model too, this must be a partial view. If there is no view specified then it simply renders the default child action.
It's not perfect but it means you can dictate which partial view you want rendered without having to clutter your macro partial with too much logic.
Passing Model Back With CurrentUmbracoPage And Surface Controllers?
Using MVC, if you post to an action do whatever logic you need. And want to pass a model back, this doesn't seem possible with Umbraco MVC?
In a normal MVC app I can just go
But it doesn't look like you can do this with Umbraco MVC? If not, when posting a form and the validation is wrong. How to you keep the form state without being able to return a viewModel?
You ca check this answer:
http://stackoverflow.com/questions/16827552/umbraco-mvc-surface-controller-cant-return-view-from-httppost-action/17509867#17509867
I too am finding this situation a little limiting, here is my fix for when you want to redirect to the current page but pass in a partial view to render and an optional model, this is an example ChangePassword Post action:
This is a new RedirectToCurrentUmbracoPage method I created:
...and finally this is the Macro Partial View:
The 2 lines at the beginning simply check for the existance of the view and model in the TempData and if found this view will render the necessary view passing in the model too, this must be a partial view. If there is no view specified then it simply renders the default child action.
It's not perfect but it means you can dictate which partial view you want rendered without having to clutter your macro partial with too much logic.
is working on a reply...