I am writing a MVC controller where I need to handle both, data return as well as a long poll "data has changed" like behavior from the SAME (!) url. NothingI can do about this - I am implementing a proxy for an already existing application, so I have no way to do any extensions / modifications to the API.
My main problem is: * The POST operations have to be completed immediately. * The GET operations take longer (can take hours sometimes).
Can I somehow rewrite both to go to different controllers? The alternative would be to... hm... make both async, just the POST is finishing right three and then.
Anyone a comment on that?
ViewData, ViewBag, and TempData are used to pass data between controller, action, and views. To pass data from the controller to view, either ViewData or ViewBag can be used. To pass data from one controller to another controller, TempData can be used.
Configure a Route Every MVC application must configure (register) at least one route configured by the MVC framework by default. You can register a route in RouteConfig class, which is in RouteConfig. cs under App_Start folder. The following figure illustrates how to configure a route in the RouteConfig class .
In Spring MVC, we can create multiple controllers at a time. It is required to map each controller class with @Controller annotation.
ASP.NET MVC Routing does the same thing; it shows the way to a request. Basically, routing is used for handling HTTP requests and searching matching action methods, and then executing the same. It constructs outgoing URLs that correspond to controller actions. Routing the map request with Controller's Action Method.
You should be able to use constraints at the routing level to control which controller/action the url goes to.
routes.MapRoute( "route that matches only GETs for your url", "your url", new { controller = "some controller", action = "some action" }, new { httpMethod = new HttpMethodConstraint("GET") } ); routes.MapRoute( "route that matches only POSTs for your url", "your url", new { controller = "some other controller", action = "some other action" }, new { httpMethod = new HttpMethodConstraint("POST") } );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With