asp.net-mvc-routing

Public action method was not found on controller

会有一股神秘感。 提交于 2019-12-01 06:41:00
I have the following controller method: public ActionResult GetResults(string viewToReturn, int resultsPerPage, string classification = null, string sessionId = null, int? lastId= null) { ... } Calling the method above via the following url: http://localhost:63455/Home/GetResults?viewToReturn=grid&resultsPerPage=30 results in an exception thrown with this message: A public action method 'GetResults' was not found on controller 'MyWebSite.Controllers.HomeController'. and here is the RegisterRoutes: ...... routes.MapRoute("Home", "home/{action}/{*qualifier}", new { controller = "Home", action =

.NET MVC custom routing

不打扰是莪最后的温柔 提交于 2019-12-01 05:47:24
问题 I was wondering if I could create a routing map with one more higher level than the controller. The typical routing would include "/controller/action/id". What I am looking for is something like "section/controller/action/id" or "controller/section/action/id". How can i do this? 回答1: No problem. Just create a route the URL of which is, for example path/to/my/application/{controller}/{action}/{id} ...and supply a default controller and action as usual. A concrete example of this is context

Public action method was not found on controller

拜拜、爱过 提交于 2019-12-01 05:26:12
问题 I have the following controller method: public ActionResult GetResults(string viewToReturn, int resultsPerPage, string classification = null, string sessionId = null, int? lastId= null) { ... } Calling the method above via the following url: http://localhost:63455/Home/GetResults?viewToReturn=grid&resultsPerPage=30 results in an exception thrown with this message: A public action method 'GetResults' was not found on controller 'MyWebSite.Controllers.HomeController'. and here is the

What is wrong with my area routing in my bin deployed MVC4 app?

谁说我不能喝 提交于 2019-12-01 05:25:55
I have just deployed an MVC4 .NET 4.0 app to my web host, for 'live' deployed testing. Non -area routes are working fine, e.g. my @Html.ActionLink("Register as a Client", "Register", "Account", new { registrationType = "Client"}, null) link works fine, and the link opens the correct page. However, with a link to an area based action like this: @Html.ActionLink("Authors", "Index", "Home", new { Area = "Author", registrationType = "Author" }, null) the link actually rendered to the browser is missing action and controller, i.e. http://mylivedomain.com/?Area=Author&registrationType=Author It may

Multiple routes assigned to one method, how to determine which route was called?

99封情书 提交于 2019-12-01 05:14:14
I am working on a small ASP.NET MVC project at the moment. The project was released a few month ago. But changes should be implemented for usability and SEO reasons now. I decided to use attribute routing to create clean URLs. At the moment a product page is called by: hostname.tld/Controller/GetArticle/1234 I defined a new Route like this: [Route("Shop/Article/{id:int}/{title?}", Name = "GetArticle", Order = 0)] public ActionResult GetArticle(int id, string title = null) { // Logic } Everything works fine, but because of backwards compatibility and SEO reasons, the old route should be still

ASP.NET route with arbitrary number of key-value pairs - is it possible?

与世无争的帅哥 提交于 2019-12-01 04:56:42
问题 I'd like to handle URLs like this: /Id/Key1/Value1/Key2/Value2/Key3/Value3/ Right now, I have set up a rule like this: /{id}/{*parameters} The parameters object is passed as a single string to all the actions that are involved in forming the response. This does work, but I have a few problems with it: Each action must resolve the string for itself. I've, of course, made an extension method that turns the string to a Dictionary<string, string> , but I'd prefer it if the dispatching mechanism

Why is ASP.NET MVC ignoring my trailing slash?

拥有回忆 提交于 2019-12-01 04:05:39
Consider the following route: routes.MapRoute( "Service", // Route name "service/", // URL with parameters new {controller = "CustomerService", action = "Index"} // Parameter defaults ); Using Url.Action("Service", "CustomerService") produces an url of /service instead of the expected /service/ Is there any way to get this to work, or do I have to resort to implementing my own routing deriving from RouteBase ? womp Legenden - there is no immediate solution to the problem. You may have run across Jason Young's blog post about the issue, which is very informative. Scott Hanselmann posted a reply

How to add route to dynamic robots.txt in ASP.NET MVC?

一曲冷凌霜 提交于 2019-12-01 04:02:08
I have a robots.txt that is not static but generated dynamically. My problem is creating a route from root/robots.txt to my controller action. This works : routes.MapRoute( name: "Robots", url: "robots", defaults: new { controller = "Home", action = "Robots" }); This doesn't work : routes.MapRoute( name: "Robots", url: "robots.txt", /* this is the only thing I've changed */ defaults: new { controller = "Home", action = "Robots" }); The ".txt" causes ASP to barf apparently You need to add the following to your web.config file to allow the route with a file extension to execute. <?xml version="1

Routing to controller with a required, non-empty Guid parameter

醉酒当歌 提交于 2019-12-01 03:58:10
I would like to map http://localhost/Guid-goes-here to ResellerController and fire Index action of that controller only when Guid-goes-here is not the empty Guid. My routing table looks like this: public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute( "Reseller", "{id}", new { controller = "Reseller", action = "Index", id = Guid.Empty } // We can mark parameters as UrlParameter.Optional, but how to make it required? ); routes.MapRoute( "Default", // Route name "{controller}/{action}/{id}", // URL with parameters new {

Html.ActionLink construct wrong link when a non-mvc route is added

为君一笑 提交于 2019-12-01 03:48:23
I have an application here with a mix of webform and mvc. I specify the routing as below routes.Add("AspxRoute", new Route("Upload/New", new WebFormRouteHandler<Page>("~/Uploads.aspx"))); routes.MapRoute( "Default", // Route name "{controller}/{action}/{id}", // URL with parameters new { controller = "Home", action = "Index", id = "" } // Parameter defaults ); So that virtual path to "Upload/New" actually maps to an aspx webform page. But my problem is that Html.ActionLink("Test", "Controller", "Action") now renders /Upload/New?Controller=Controller&Action=Action Having looked at the MVC