There isn't any special kind of routing. What you're trying to do could also be done in a Controller, but I don't know if that will make any difference. You could also just use the umbracoRedirect property and select the parent node through the picker.
I just wanted to make sure there wasn't a reason before I invest some time making it work.
I don't want to use umbracoRedirect because I'm wanting to use it with the DateFolders package. There will be lots of these folders and I want something automatic.
I can ertainly make it work using RedirectToUmbracoPage() like you have shown with the Contact controller.
return RedirectToUmbracoPage(child);
I've got my RedirectToParent View already (it had the non working code in it). To make it work through the a controller it means I'll have to also create a RedirectToParentModel and RedirectToParentController.
I'm happy to do this but is seems like a lot of extra things just to make the redirect work. The new model in particular seems pointless as it won't be adding anything. Is there a better way?
Can you show how your current code looks like. If you have a normal template that doesn't have custom model you can also do this in the controller:
public class ContactController : BaseSurfaceController
{
public ActionResult Contact(RenderModel model)
{
//Do logic here without custom model
return CurrentTemplate(model);
}
}
Your template isn't even hit right know because it will first hit the controller before the template and that's where you do the redirect. Might be good do add some comment in the view that it's not getting hit and only is used for redir in the controller. Did that myself too a couple of times :-).
Response.Redirect
I want a template that will just redirect the user to the parent page for certain nodes that shouldn't be accessed.
I've created a template/view which contains the following
however it does not appear to be working, I get just a blank page and the URL shows the page that we are supposed to be redirecting from.
I've used this before with web forms so is there something in the framework that is stopping this from working? Some kind of special routing?
Regards,
Matt
Hello,
There isn't any special kind of routing. What you're trying to do could also be done in a Controller, but I don't know if that will make any difference. You could also just use the umbracoRedirect property and select the parent node through the picker.
Jeroen
Thanks Jeroen,
I just wanted to make sure there wasn't a reason before I invest some time making it work.
I don't want to use umbracoRedirect because I'm wanting to use it with the DateFolders package. There will be lots of these folders and I want something automatic.
Regards,
Matt
I can ertainly make it work using RedirectToUmbracoPage() like you have shown with the Contact controller.
I've got my RedirectToParent View already (it had the non working code in it).
To make it work through the a controller it means I'll have to also create a RedirectToParentModel and RedirectToParentController.
I'm happy to do this but is seems like a lot of extra things just to make the redirect work. The new model in particular seems pointless as it won't be adding anything.
Is there a better way?
Thanks, Matt
Can you show how your current code looks like. If you have a normal template that doesn't have custom model you can also do this in the controller:
That will also work. The model will be created by Umbraco. It's the same as in these examples: http://our.umbraco.org/documentation/Reference/Mvc/custom-controllers
Jeroen
Thanks Joroen,
The answer occurred to me whilst having lunch and my mind was off the subject.
I have done as you have suggested I think, created a new action in the default controller and then just called it in the template view.
public ActionResult RedirectToParent()
{
return Redirect(CurrentPage.Parent.Url);
}
I'm slowly getting to grips with the MVC way of doing things. I'm a big advocate of your Hybrid framework for learning it.
Cheers, Matt
Adding that ActionResult to the default controller is a great solution! Nice thinking :-).
Jeroen
Maybe I misread. Do you call that method in your template view with an Html.Action?
If the name of the template is the same as the name of the ActionResult in the default controller you might be able to route hijack to it.
Also you can do a redir like this:
Not really sure what the benefit is ;-).
Jeroen
Ah, I get it. Yes the ActionResult is the same name as the template so I've taken out the explicit call to Html.Action and it still works. :-)
I've also made use of
RedirectToUmbracoPage
Cheers, Matt
Your template isn't even hit right know because it will first hit the controller before the template and that's where you do the redirect. Might be good do add some comment in the view that it's not getting hit and only is used for redir in the controller. Did that myself too a couple of times :-).
Jeroen
Ah that's good to know. I was wondering how the flow worked.
is working on a reply...