asp.net-mvc-routing

MVC 3 Can't pass string as a View's model?

倾然丶 夕夏残阳落幕 提交于 2019-12-20 10:15:12
问题 I have a strange problem with my model passed to the View Controller [Authorize] public ActionResult Sth() { return View("~/Views/Sth/Sth.cshtml", "abc"); } View @model string @{ ViewBag.Title = "lorem"; Layout = "~/Views/Shared/Default.cshtml"; } The error message The view '~/Views/Sth/Sth.cshtml' or its master was not found or no view engine supports the searched locations. The following locations were searched: ~/Views/Sth/Sth.cshtml ~/Views/Sth/abc.master //string model is threated as a

ASP.NET MVC - MapRoute versus routes.Add (and 404s)

别等时光非礼了梦想. 提交于 2019-12-20 09:53:37
问题 I'm just getting started with ASP.NET MVC. What is the difference between MapRoute and routes.Add ? Should I just be using MapRoute? Can I map multiple routes? Which "maps" take precedence... those you called first or last? I'd like to be able to do something similiar to the StackOverflow does for users. But I would like the URL to fit this pattern: "User/{domain}/{username}" to be routed to a UserController and for all other requests to do the typical ASP.NET MVC routing. ex: routes.MapRoute

Force all Areas to use same Layout

我们两清 提交于 2019-12-20 08:32:23
问题 I have the following project structure: /Views/Shared/_Layout; /Areas/Area1/Views/ControllerName/Index; ... /Areas/AreaN/Views/ControllerName/Index. Is there any way to force all areas to use the _Layout as a base layout ? Is there any way to do it without adding the _ViewStart file (for example, via the routing configuration)? See Also: How do I specify different Layouts in the ASP.NET MVC 3 razor ViewStart file? 回答1: You just have to add a file named: _ViewStart.cshtml Under each area views

Force all Areas to use same Layout

社会主义新天地 提交于 2019-12-20 08:32:22
问题 I have the following project structure: /Views/Shared/_Layout; /Areas/Area1/Views/ControllerName/Index; ... /Areas/AreaN/Views/ControllerName/Index. Is there any way to force all areas to use the _Layout as a base layout ? Is there any way to do it without adding the _ViewStart file (for example, via the routing configuration)? See Also: How do I specify different Layouts in the ASP.NET MVC 3 razor ViewStart file? 回答1: You just have to add a file named: _ViewStart.cshtml Under each area views

Setup a route {tenant}/{controller}/{action}/{id} with ASP.NET MVC?

我与影子孤独终老i 提交于 2019-12-20 08:05:37
问题 I would like to setup a multi-tenant ASP.NET MVC app. Ideally, this app would have a route with {tenant}/{controller}/{action}/{id} , each tenant representing an logical instance of the app (simply independent multi-user accounts) The fine grained details how do that are still quite unclear to me. Any guide available to setup such multi-tenant scheme with ASP.NET MVC? 回答1: I am currently working on a similar project using ASP.Net MVC, Forms Authentication and the SQL providers for Membership

ASP.NET MVC routing: with querystring to one action, without to another

橙三吉。 提交于 2019-12-20 04:34:27
问题 I need the following routes: example.com/products goes to a product categories page (e.g. cars, trucks, buses, bikes) controller= Products , action= Categories() example.com/products?a=1&b=2 goes to an index of all products in a particular category (e.g. Ford, Honda, Chevy) controller= Products , action= Index(string a, string b) The routes only differ on the querystring, and it seems that MVC ignores anything after the "?". So of course only one rule will ever get hit--the first one. How do

How do I 301 redirect /Home to root?

℡╲_俬逩灬. 提交于 2019-12-20 02:57:21
问题 Here is my route in Global.asax to remove /Home: routes.MapRoute("Root", "{action}/{id}", new { controller = "Home", action = "Index", id = UrlParameter.Optional } ); Well I need to setup a 301 redirect because someone linked to /Home and they're getting a 404. So how do I setup the 301? I checked the way the route was setting up and it is looking for a "Home" action method in the "Home" controller. So obviously I could add: public ActionResult Home() { Response.Status = "301 Moved

Current URL in ASPCore Middleware?

五迷三道 提交于 2019-12-20 02:47:33
问题 Is there a way I can access the current Requested URL in ASPCore 2.0 Middleware? Is there something I can Inject? 回答1: HttpContext object will be passed to the Invoke method of your middleware. You can access the Request property on that. You can use the GetDisplayUrl extension method or GetEncodedUrl extension method. public Task Invoke(HttpContext context) { var url1 =context.Request.GetDisplayUrl(); var url2 = context.Request.GetEncodedUrl(); // Call the next delegate/middleware in the

Controller without the controller suffix

牧云@^-^@ 提交于 2019-12-20 02:38:07
问题 based on my design requirements, I will like to exclude the suffix 'Controller' from my controllers and replace it with 'Resource'. So that 'FundsController' will become 'FundsResource'. The problem is that I am not able to route to my specified actions by either convention based or attribute routing when I change replace the term 'Controller' and get an error saying that the controller with this name could not be found. How can I satisfy the above mentioned design requirement and also be

Attribute Routing with Multiple Leading Zero Decimals

老子叫甜甜 提交于 2019-12-20 02:29:39
问题 Current ActionResult: [Route("EvaluatorSetup/{evalYear}/{department}")] public ActionResult RoutedEvaluatorSetup(int evalYear, string department) { return EvaluatorSetup((int?)evalYear, department); } I would like to use the url: /EvaluatorSetup/2014/001.3244 where the {department} is a ultimately a string, however, the routing is not picking up {department} as a string. A. I don't know what type MVC is expecting for "001.3244", or what it is picking it up as. B. I want to maintain it as a