I am using a surface controller and it is working well for the forms. It even respects the authorize attribute I have applied to the controller (though this is due to child actions).
@Html.Action("MyForm", "MyController")
[Authorize]
public class MyController : SurfaceController
{
public ActionResult Index()
{
//Todo: Redirect Logic
return CurrentUmbracoPage();
}
[ChildActionOnly]
public ActionResult MyForm()
{
return View();
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult FormSubmit(myModel model)
{
if (!ModelState.IsValid)
return CurrentUmbracoPage();
return RedirectToUmbracoPage(1234)
}
}
I now however wish to add another check and redirect the user accordingly. I cannot do this inside the child actions and need to do this on the main call to the page.
I tried creating a method call index however it is never hit. I suspect the authorize attribute is only working as a child action is hit.
My Controllers are in a different assembly to the main site but I do not think this is an issue.
Surface Controller index Method not Hit
I am using a surface controller and it is working well for the forms. It even respects the authorize attribute I have applied to the controller (though this is due to child actions).
Controller
I now however wish to add another check and redirect the user accordingly. I cannot do this inside the child actions and need to do this on the main call to the page.
I tried creating a method call index however it is never hit. I suspect the authorize attribute is only working as a child action is hit.
My Controllers are in a different assembly to the main site but I do not think this is an issue.
Any ideas?
Could you please post the code you use to call your index method of your controller ?
I am just using navigating to the URL of the published page that has the same name as the surface controller and the template.
The code above is just sample code but it would be http://testdomain.com/My
Yeah you see, that will not work, Umbraco does not work that way, if you want to get hold of you index method you need to do this
Where the things inside the parenthases are what your values should be.
Hope it makes sense :)
Casper
How can I redirect if some data is missing on a standard page or do I need to use an RenderMvcController instead.
If use the RenderMvcController then I do not have access to the methods needed for the form post.
Depends on where you want to redirect to if you just want to redirect back to the same page, you can use
and if you want to go to another Controller Method you can do
And to redirect to a different page you can use
What I mean is if I change to use the RenderMvc Controller RedirectToCurrentUmbracoPage and simmilar methods are not available.
That is true, but SurfaceController derives from RenderMVCController i believe
is working on a reply...