I think you're confusing 2 things: RenderMvcController and SurfaceController.
You need a separate controller (inheriting from SurfaceController) to post your forms to. In that controller you process the posted model and do return RedirectToCurrentUmbracoPage(); when everything works out okay.
Then the AnimalIndexmethod on your RenderMvcController will be used again.
You should've been taught in the master classes that it's best to use:
return CurrentUmbracoPage();
when there's validation errors. This will get you back to the page that you were on with the model populated the way it was before you posted the form and errors added to it.
Postback to RenderMvcController not working...Edit
I have to integrate some MVC 4 login in Umbraco about a thousands records table, some crud logic cant get the post working.
This is what i made so far.
The model:
This all is merged from working MVC 4 to Umbraco. The controller looks like:
And the view for the AnimalEdit is build up as next:
Could not find a Surface controller route in the RouteTable for controller name AnimalController
This means i need to use a controller for display and a controller for posting.....
Has nobody a working solution without installing a complete framework?
I think you're confusing 2 things:
RenderMvcController
andSurfaceController
.You need a separate controller (inheriting from
SurfaceController
) to post your forms to. In that controller you process the posted model and doreturn RedirectToCurrentUmbracoPage();
when everything works out okay.Then the
AnimalIndex
method on yourRenderMvcController
will be used again.Hi Sebastiaan, that is an scenario i read about and will ook like this. A new controller that inherits from SurfaceController:
and a change the view, the form statement:
This results in the notorious error:
No parameterless constructor defined for this object.
Does this help? http://stackoverflow.com/questions/17293530/in-umbraco-6-1-1-mvc-4-how-can-i-do-a-form-post-back-to-a-surface-controller-us
Bingo! These extra constructors did the trick. Thanks a lot!
One more thing....
Returning from a valid post went ok while i am using
but what about returning from invalid post and sending the viewmodel back. In normal MVC we do this:
but in Umbraco the viewmodel get malformed. Type information is lost and the YSOD appears.
You can also use the SurfaceController and combine it with the IRenderMvcController interface to do both: https://github.com/jbreuer/Hybrid-Framework-for-Umbraco-v7-Best-Practises/blob/master/Umbraco.Extensions/Controllers/Base/SurfaceRenderMvcController.cs#L14
Now you can have 1 controller for route hijacking and posting.
Jeroen
@Willem:
You should've been taught in the master classes that it's best to use:
when there's validation errors. This will get you back to the page that you were on with the model populated the way it was before you posted the form and errors added to it.
is working on a reply...