asp.net-mvc-routing

MVC 4 Default Parameter Value

血红的双手。 提交于 2020-01-04 08:29:11
问题 In MVC 4 application while defining routing I can provide a list of default parameters. What value shall I provide for optional parameter: UrlParameter.Optional or empty string ? Examples: routes.MapRoute("simple", "{controller}/{action}/{id}", new {controller = "Home", action = "Index", id = UrlParameter.Optional}); routes.MapRoute("simple", "{controller}/{action}/{id}", new {controller = "Home", action = "Index", id = ""}); Is there any difference between id = "" and id = UrlParameter

MVC 4 Default Parameter Value

£可爱£侵袭症+ 提交于 2020-01-04 08:29:05
问题 In MVC 4 application while defining routing I can provide a list of default parameters. What value shall I provide for optional parameter: UrlParameter.Optional or empty string ? Examples: routes.MapRoute("simple", "{controller}/{action}/{id}", new {controller = "Home", action = "Index", id = UrlParameter.Optional}); routes.MapRoute("simple", "{controller}/{action}/{id}", new {controller = "Home", action = "Index", id = ""}); Is there any difference between id = "" and id = UrlParameter

parameters in routing do not work MVC 3

眉间皱痕 提交于 2020-01-04 03:58:01
问题 I am sure I am doing something wrong, but after spending a few hours on this with no luck, I would be really happy if someone can help me out with this. Seems like the routing system honors the parameters only in the first routing registration. This is how my global.asax.cs looks like using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using System.Web.Routing; namespace MvcApplication4 { public class MvcApplication : System.Web

parameters in routing do not work MVC 3

拟墨画扇 提交于 2020-01-04 03:55:05
问题 I am sure I am doing something wrong, but after spending a few hours on this with no luck, I would be really happy if someone can help me out with this. Seems like the routing system honors the parameters only in the first routing registration. This is how my global.asax.cs looks like using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using System.Web.Routing; namespace MvcApplication4 { public class MvcApplication : System.Web

Web API action not found when optional parameter not present in URL

℡╲_俬逩灬. 提交于 2020-01-04 02:48:10
问题 please help. I had to change routing for Web API to be able to use methods in URL: public class RouteConfig { public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); // for MVC controllers routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "Editions", action = "Index", id = UrlParameter.Optional } ); // for Web API routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/

ASP.NET MVC C# Routing - Passing a null integer

怎甘沉沦 提交于 2020-01-04 02:11:06
问题 I'm working with MVC 3 in a web app and i'm facing a problem in routing. I'm defining my router handler like this: routes.MapRoute( "Users", "{controller}.aspx/{action}/{id}/{page}", // URL with parameters new { controller = "Users", action = "Details", id = UrlParameter.Optional, page = UrlParameter.Optional } // Parameter defaults ); The url is: http://app.domain/Users.aspx/Details/114142/5 (example) I'm sucefully getting the id of the user, but i can't get the page number. The controller

Other errors find my Error.cshtml, why doesn't 404 error find Error.cshtml?

不羁的心 提交于 2020-01-03 08:06:31
问题 I am tackling ASP.NET, MVC 3, web development, for the first time, all at the same time. Please bear with me, as I know this subject has been discussed heavily from different angles. I still have not found the answer to my specific question: Why doesn't my application find my Error.cshtml file when a 404 occurs, when it finds it just fine with other errors? (Environment: Win 7 64bit, IIS7, SQL 2008 Express, VS2010, ASP.NET 4, MVC3, EF v4) I have a controller, WorkerController.cs, that

Asp.net MVC Catchall Routing in a Sub Application

天涯浪子 提交于 2020-01-03 06:59:07
问题 I have an MVC application with a sub application running another MVC project in IIS. Both use the same version framework and run on separate application pools. My problem is, I cannot get the sub application to work inside this virtual application folder of the root site. I get a 403.14 Forbidden error . If I enable directory listing on the sub application I just get a list of the MVC application files. I think, I have narrowed the problem down to routing; The sub application has a custom

How do I change the order of routes.MapRoute in MVC3?

无人久伴 提交于 2020-01-03 02:54:07
问题 How do I change the order of the url parameter when registering routes in global.asax.cs? I registered the route like so: (Note: I also have the default MVC3 route registered as well) routes.MapRoute( "SurveyWizard", "survey/{id}/{action}", new { id = UrlParameter.Optional, action = "AddQuestions" }); My controller: public ActionResult AddQuestions(int id) { if(id < 1 || id == null) //Redirect somewhere var survey = _surveyService.GetSurveyById(id); //other controller logic return View(survey

User routing in ASP.NET MVC for urls like www.website.com/users/jeffAtwood

送分小仙女□ 提交于 2020-01-03 02:49:08
问题 I am trying to show user details at the following url : www.website.com/users/yasser where the last entry yasser is the username I have tried a couple of routes but it just does nt work. My User controller is as shown below. public class UserController : Controller { public ActionResult Index(string username) { var model = _service.GetUserDetails(username); return View(model); } } I have reffered this and couple of other links, but I really could not figure out how it worked. Can some one