asp.net-mvc-routing

ASP.NET MVC - Routing - an action with file extension

谁说我不能喝 提交于 2019-12-28 03:02:09
问题 is there a way to achieve calling URL http://mywebsite/myarea/mycontroller/myaction.xml This would basically "fake" requesting a file but the result would be an action operation that would serve a file created dynamically? I tried this: context.MapRoute( "Xml_filename", "Xml/{controller}/{action}.xml" ); but whenever there is a filextension in the URL the routing fails and behaves as I was requesting a file directly. I suspect this might be because of using extension less url handler. <add

How can I execute PHP code from ASP.NET MVC

淺唱寂寞╮ 提交于 2019-12-25 16:56:20
问题 I want to do something like the following: public class HomeController : Controller { // Redirect to the phpinfo.php file public ActionResult PhpInfo() { return RedirectToRoutePermanent("~/Views/Home/PhpInfo.php"); } } This errors out saying that the route cannot be found. Any ideas? Thanks, Zain 回答1: Answer from scartag in the comments. Stating it below for posterity: It doesn't seem to be possible using the C# part of ASP.NET, but you can post links by using <a href="/PhpInfo.php">PHP Info<

Multiple controller types were found that match the Requested URL

自作多情 提交于 2019-12-25 14:45:23
问题 I have enable attribute routing in route config file and I have declare attribute routing as [RoutePrefix("receive-offer")] public class ReceiveOfferController : Controller { // GET: ReceiveOffer [Route("{destination}-{destinationId}")] public ActionResult Index(int destinationId) { return View(); } } public class DestinationController : Controller { [Route("{country}/{product}-{productId}")] public ActionResult Destination(string country, string product, int productId) { return View(); } }

Delete route not being hit

安稳与你 提交于 2019-12-25 08:29:16
问题 Being battling this issue for too long now it's time to ask for help. The delete route of my .net core mvc app is not being hit. All other routes (Get, Post) are hit just fine. The route config at startup looks like this: app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller}/{action}/{id?}"); }); The form submit looks something like this: <a class="btn btn-primary" href="~/DisabledRegistrations/Delete/@(Model.Id)">Confirm</a> The controller method looks like this:

Lavavel 5.2.36 MethodNotAllowedHttpException in RouteCollection.php line 218:

杀马特。学长 韩版系。学妹 提交于 2019-12-25 07:35:14
问题 Hi I am fairly new to Laravel and am trying to implement a post request for a simple form. I have been following a YouTube Tutorial series (laravel 5 | Section 3 | Part 4 Routing POST Requests) however at 5:46mins in, there is a notification that this method is only applicable to versions prior to Laravel 5.2. I have tried to edit the VerifyCsrfToken.php method protected $except = ['api/']; but this makes no difference. My routes.php code snippet: Route::post('/form-handler', function(

register route with character

瘦欲@ 提交于 2019-12-25 07:30:13
问题 I have controller with 2 methods, with following signature: public class TestController { [HttpGet] public ActionResult TestMethod1() { //here code return Json(1, JsonRequestBehavior.AllowGet); } [HttpGet] public ActionResult TestMethod2(long userId) { //here code return Json("userId= " + userId, JsonRequestBehavior.AllowGet); } } I want to create the following routers for this methods: For the first method: http://domain/test/ For the second method: http://domain/test?userId={userId_value} I

How do you Route a page to an Attribute Route in MVC 5

帅比萌擦擦* 提交于 2019-12-25 07:27:47
问题 I'm in the process of migrating some of our legacy aspx pages to a shiny new MVC based architecture. However, during the transition, I still need to support the old routes, and just either redirect, or render the relevant mvc action. The issue I have is that 1 aspx that used to handle multiple purposes is now multiple MVC actions. I figured that I could use a custom RouteBase with: routes.Add("legacy", new LegacyPageOverride()); That looks like: public override RouteData GetRouteData

Change URL of action in mvc

こ雲淡風輕ζ 提交于 2019-12-25 04:29:07
问题 Is there a way to change the URL of a given action in mvc without changing the action or controller called? If so, how would this be done on the following MapRoute: routes.MapRoute( "Estate.CloseDeal", "Estate/CloseDeal/{groupId}/{paymentType}/{mortgageValue}/{province}", new { controller = "Estate", action = "CloseDeal" }, new { groupId = "\\d+", paymentType = "\\d+", mortgageValue = "\\d+", province = "\\d+" } ); The desired URL is: ".../estate-support/deal-closing/...". Currently it

MVC Routing with multiple parameters is not working

試著忘記壹切 提交于 2019-12-25 03:05:19
问题 Hey All I Added two custom routes routes.MapRoute( "ParentCat", "{PCat}/{id}", new { Controller = "Adds", Action = "DetailWanted", PCat = UrlParameter.Optional, id = UrlParameter.Optional }); routes.MapRoute( "SubCat", "{PCat}/{SCat}/{id}", new { Controller = "Adds", Action = "DetailWanted", PCat = UrlParameter.Optional, SCat = UrlParameter.Optional, id = UrlParameter.Optional }); for the urls localhost:2110/Category/addid & localhost:2110/Category/SubCategory/addid but debugger straight

ASP.NET MVC route for serverside imagemap

蓝咒 提交于 2019-12-24 20:56:47
问题 I've got an <input type='image'> in an ASP.NET MVC view, but I'm not sure how to retrieve the coordinates in the action that runs when the form is submitted. The requested URL looks like /Map/View/?map.x=156&map.y=196 but I can't just do public ActionResult View( int map.x, int map.y ) { ... } because they're obviously not valid names for C# method parameters. Is there any equivalent of the ActionName attribute to map query parameters to method parameters? 回答1: You have to use use Model