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..
Related
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.
My situation is: I have a Spring MVC project is running now, I need to include a file in normal form object to submit to server side to handling.
I did quite lots research recently, I found there is no way to submit a file in a regular form as file upload submit form has to configured to support file encode (enctype="multipart/form-data"). it is impossible in regular form.
Ajax provides a way to do the file uploading in javascript by javascript function call, but they need a individual servlet to listen to the javascript call. My project already did everything in modelandview controller to handle form object and model object logic.
My question is: May I add a file upload method in my modelandview controller to listen to my Ajax function call? If it is true, what's looks like?
Please help!!
After a while works on this issue, I found some thing is very interesting. If I want to use some thing else in my Spring MVC controller. I have change my controller class to "extends MultiActionController", which means make the controller to support multiAction, and then you can add other class and action in Spring MVC modelandview style controller, even you can use "webservlet" or "ResponseBody" style controller functions in your MVC controller, you don't need create other new controller to support Ajax controller, you only need update your existing controller by adding some functions. it is much easy to manage you existing code too.
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 using extjs mvc style to create a web application.
I don't have any direct issue but I'm not sure on how should I handle this code to keep following the mvc pattern.
This is my situation:
Controller, which detect click event
View, which has a changePassword method
I'm simply trying to make an ajax request to change the password of a user (notice that the code is currently working, I'm only thinking if I should move a part on the controller).
Currently the code behaves like this:
Controller detect click event and run changePassword method on the view with a record parameter it passes to
View open a prompt message that request to the user a new password
View runs an ajax call and show a successful/error message
What my idea is:
Controller detect click event and run View.showChangePassword prompt
View show the prompt and it returns the password insert there to the controller
Controller runs the ajax call
Controller runs a View.showChangePasswordResult with param: what is returned by ajax call
Is my idea better than what I'm currently using?
Yes. I would only move showChangePassword to the controller too.
Controller detects event
Controller create another view if necessary and subscribe to submit method of this view
Controller submits values via Ajax.
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.