routing

Appending ?param= to mvc routes

一个人想着一个人 提交于 2019-12-01 16:56:43
Some MVC sites have querystring params appended to the route Url (of which I noticed StackOverflow does), such as: https://stackoverflow.com/questions/tagged/java ?page=9802&sort=newest&pagesize=15 What are the advantages of having the parameters as more conventional ?querystring params, rather than /param/values/ ? Also, how are these params appended to routes that have been set up? I'm familiar with setting up mvc routes with params like "users/details/{id}" etc. but don't know how to configure routes for use with 1 or more ?params as per the example url above? Query string parameters are

Overriding params in nested routes

梦想与她 提交于 2019-12-01 16:37:06
I want to have consistency in naming convention of my routes. Default param is :id for any resource. However if one nests another resource in it, param of parent resource changes to :parent_id . My routing looks like: resources :users do resources :projects do resources :issues end end For user model it would generate url like :id , for project url will be :user_id/:id and for issues url will be :user_id/:project_id/:id . I tried to overload the default param following this resources :users, param: :user_id do resources :projects, param: :project_id do resources :issues, param: :issue_id end

Use MVC routing to alias a controller

血红的双手。 提交于 2019-12-01 16:09:58
I have a controller called InstallationController , and a fancy report representation of an installation called a Rate Card , but the end user insists on calling installations themselves Rate Cards . I would like him to see the URL http://site/RateCard/Edit/3 , where this gets routed actually as http://site/Installation/Edit/3 . How can I do this in MVC 3 RC2? A couple of options are, you can either rename the controller to RateCardController , or add a new route that directs to the Installation controller, like: routes.MapRoute( "RateCard", // Route name "RateCard/{action}/{id}", // URL with

ASP.NET Routing in Global.asax

房东的猫 提交于 2019-12-01 16:03:41
I'm trying to add a route in my web forms application by following this: http://msdn.microsoft.com/en-us/library/cc668201.aspx#adding_routes_to_a_web_forms_application I've added the route in my Global.asax file like so: public static void RegisterRoutes(RouteCollection routes) { routes.MapPageRoute("", "/WebsiteName/{combinedPin}", "~/Default.aspx"); } I then try to visit my website locally like this: http:// localhost:12345/WebsiteName/test36u But I get a resource cannot be found message so I don't think my route is correct. Can anybody see a problem with my code? Any pointers would be much

Overriding params in nested routes

给你一囗甜甜゛ 提交于 2019-12-01 15:58:47
问题 I want to have consistency in naming convention of my routes. Default param is :id for any resource. However if one nests another resource in it, param of parent resource changes to :parent_id . My routing looks like: resources :users do resources :projects do resources :issues end end For user model it would generate url like :id , for project url will be :user_id/:id and for issues url will be :user_id/:project_id/:id . I tried to overload the default param following this resources :users,

Optional routing parameter with constraint in ASP.NET MVC 2?

ⅰ亾dé卋堺 提交于 2019-12-01 15:20:42
问题 If I have a route like this: routes.Add(new Route("{controller}/{page}", new RouteValueDictionary { { "page", UrlParameter.Optional } }, new RouteValueDictionary { { "page", @"[Pp]age\d+" } }, new MvcRouteHandler() )); Then the route doesn't match when {page} is missing, however if I remove the constraint it matches. Is this a bug or a feature? 回答1: It's a feature: how can the constraint match if the parameter if optional? You might either want to set the default value for "page" to "Page1"

ASP.NET MVC routing fails when using default.aspx/controller/action style url

≯℡__Kan透↙ 提交于 2019-12-01 14:31:38
I'm deploying an ASP.NET MVC site to a IIS6 webserver, so I'm using a default.aspx/{controller}/{action} style routing strategy. However, for some reason it doesn't really work when using the default.aspx part. No matter the url, it always gets the default action (Index) on the default controller (Public). I've been using the excellent Routing Debugger to see what's going on. route fail http://img169.yfrog.com/img169/7532/routefail.gif As you can see I'm requesting default.aspx/contact , which should match the 3rd route in the table. Actually ANYTHING I write after default.aspx/ matches the

Regex in Route attribute - RESTful API ASP.NET Web API

自古美人都是妖i 提交于 2019-12-01 14:29:41
I've got a problem with regular expressions in Route attribute. I'd like to create RESTful API, where you can specify start date and end date in URL to filter results. What I've done till now is: [HttpGet] [Route("date/{startDate:datetime:regex(\\d{4}-\\d{2}-\\d{2})}/{*endDate:datetime:regex(\\d{4}-\\d{2}-\\d{2})}")] [Route("date/{startDate:datetime:regex(\\d{4}/\\d{2}/\\d{2})}/{*endDate:datetime:regex(\\d{4}/\\d{2}/\\d{2})}")] public IEnumerable<Recommendation> GetRecommendationByDate(DateTime startDate, DateTime? endDate) { var output = db.Recommendations .Where(r => r.IsPublished == true &&

Use MVC routing to alias a controller

ε祈祈猫儿з 提交于 2019-12-01 14:26:16
问题 I have a controller called InstallationController , and a fancy report representation of an installation called a Rate Card , but the end user insists on calling installations themselves Rate Cards . I would like him to see the URL http://site/RateCard/Edit/3, where this gets routed actually as http://site/Installation/Edit/3. How can I do this in MVC 3 RC2? 回答1: A couple of options are, you can either rename the controller to RateCardController , or add a new route that directs to the

how to remove action name from URL in cakephp2

久未见 提交于 2019-12-01 14:24:22
may be duplicate but I don't get any proper answer or help actually I want to do like: my current URL is : http://mysite.com/MyController/view/page1 but I want something like : http://mysite.com/MyController/page1 means I want to hide action name from URL. I have used Router::connect('/:controller/:id',array('action' => 'view'),array('id' => '[0-9]+')); but its not working for me below one working fine but Router::connect('/:controller/*', array('action' => 'view'),array('id' => '[0-9]+')); it applies for all controller but I wanted to apply for specific controller use Router::connect('