Is there some way to do a forward in Codeigniter? I need to call another method of my controller in the same requisition, but the redirect will do another requisition.
Related
Can I create a redirect to view in another folde, by calling a webapi controller in MVC method?
I need a simple solution/method to call. I will refactor the rest later..
I am using Refinery CMS on Ruby on Rails and I need to know, if it's possible to inherit some method from an admin controller in a front-end controller?
I require the same method in the backend and the frontend, but I want them to redirect differently. From the frontend I want to redirect to a frontend page without a show action and from backend I want to redirect to the show action of the added item.
How?
If you really want to share a method you can always write it inside a module that you include in both controllers, however it might not turn out very nice. As you want to redirect differently you will have to know about both contexts. In the worst case you would switch on the type of controller you are included in, but hopefully you can switch depending on the role of the user, such that you do not need to know about the two controllers in your module.
Is there a way to create an Ajax folder inside application, so that I can then add each controllers ajax as a seperate controller in that ajax folder?
For instance, say I have IndexController, EmployeeController, MemberController. Inside Ajax folder, I want to have the same three names as well.
Then If I want to call an ajax action, I could refer to /ajax/member/whatever.
Is this possible with zend?
You could set up routes to create urls like that, but I wouldn't duplicate the controllers as you're suggesting. One controller can handle both html and ajax requests. You could include a format parameter in your url like this: /member/21/format/ajax
Then the member viewAction can check the format variable. If it's ajax, you can disable your layout and return the ajax response.
I'm working on a project converting older .aspx pages to newer MVC pages. I'm currently using the routing function to map the existing legacy pages to use the newer MVC pages behind the scenes. This is working great because it is preserving the existing URL, however, whenever the controller needs to redirect the user OR an MVC Url.Action link is used, the URL it sends the user to is the MVC url and not the routed legacy page url. I realize that this is how its suppose to be functioning out of the box but I was wondering if MVC has "reverse routing" functionality of some sort. By reverse routing I am looking for something that allows the Url.Action("action") to return the routed .aspx associated url with the specified action instead of the default /controller/action link.
So for instance,
here is a sample route
context.MapRoute("AboutUs", "pages/aboutus.aspx", new { controller = "default", action = "aboutus" });
This enables domain.com/pages/aboutus.aspx to run the new MVC action "aboutus" from the DefaultController behind the scenes perfectly.
However, if on another MVC page I have a link created by
Url.Action("aboutus")
it points them to domain.com/mvc/aboutus. I would like it to point them to domain.com/pages/aboutus.aspx to keep uniformity across the site.
Thanks for any insights that you can provide. I might end up having to override the Url.Action method to look up the route and return the mapped url but I just wanted to check for existing functionality so I don't reinvent the wheel.
Try using the RouteUrl extension method, which matches the route by route name rather than route parameters, like so:
Url.RouteUrl("aboutus") // route name
MSDN: http://msdn.microsoft.com/en-us/library/dd460347
I have an http handler which picks up all requests for my custom extension .page . This works fine with old fashion asp.net where I simply do a Server.Transfer to the aspx file of choice.
However, I would like to move this to MVC and instead reroute to either a Controller or a View. Doesn't matter which though I would prefer to a Controller.
Any help on this subject is appreciated.
Thanks!
I'd go about adding a new entry in the RouteTable.Routes ignored routes:
routes.Ignore("{*allcustomextension}",
new {
allcustomextension = #".*\.ext(/.*)?"
});
This will allow the handler to be invoked as a physical resource.
To redirect from the handler context to a View use:
System.Web.Mvc.UrlHelper.Action("ViewName", "ControllerName");
Firstly, you should redirect only to a controller which will select the view to render but think that you don't need that custom handler. Try something like that (you should change it somehow to match the url format you have)
routes.MapRoute("page", "{controller}/{action}.page");
If that doesn't work and you really want to redirect from your handler, combine the ignoring route from Xander with
Response.Redirect(System.Web.Mvc.UrlHelper.Action("ActionName", "ControllerName"));
Afaik, Server.Transfer works only with asp.net classic so your only option is a redirect.