asp.net-mvc-areas

Autofac Dependencies Per Area

蹲街弑〆低调 提交于 2019-12-23 02:52:33
问题 I'm creating a new MVC4 site using Autoface that has a public consumer site as well as an admin area for managing the consumer facing site. The admin site will be located in a different area be using the same services as the consumer facing site, but will not having some of the custom branding features. I've followed the advice given elsewhere of having a ViewDataFactory which provides a set of shared data for the view to use. My goal is to provide a different ViewDataFactory depending on

ASP.NET MVC area namespace problem

三世轮回 提交于 2019-12-22 04:37:30
问题 I create a new area in my asp.net mvc 3 solution named admin . Visual studio automatically assign the names space: MyApp.areas.admin.controllers I change this to MyApp.admin.controllers But it stops resolving the action. Any help in this regard will be appreciated. Thanks 回答1: You need to specify the new namespace when registering the route for your admin area. In your \Areas\admin\adminAreaRegistration.cs file, you need to modify the RegisterArea() method as follows: public override void

Get current action and controller and use it as a variable in an Html.ActionLink?

对着背影说爱祢 提交于 2019-12-22 03:50:13
问题 I need to be able to dynamically retrieve the current action and controller name of whatever page you're on, and actually use them to create a new HTML.ActionLink that links to the same action and controller name, but in a different area. So I guess I need to retrieve the current action and controller name as variables to use in building a new HTML.ActionLink. So, if I'm on the www.site.com/about page, I need to have a link dynamically generated to the www.site.com/es/about page. I've

How to specify default Area without adding area = “” to every ActionLink

╄→尐↘猪︶ㄣ 提交于 2019-12-21 03:49:21
问题 I have a large existing application built on ASP.NET MVC2 RC2. All of my links look like this: htp//site/controller/action/id I just added an Area called: BigBird . Now when I'm in the BigBird area, all of my links look like this: htp://site/ BigBird /controller/action/id Problem is that none of those controllers/actions exist in my new Area. So I have to go through all of my actionlinks all over my application and put this routevalue: area = string.empty Is there any way around this? 回答1: I

ASP.NET MVC Default routes accessible via area routes

为君一笑 提交于 2019-12-20 12:38:29
问题 So far (for brevity) I have one route in global.asax registered like this: routes.Add(new LowercaseRoute("{action}/{id}", new MvcRouteHandler()) { Defaults = new RouteValueDictionary(new { controller = "Home", action = "Index", id = UrlParameter.Optional }), DataTokens = rootNamespace }); Where "rootNamespace" is var rootNamespace = new RouteValueDictionary(new { namespaces = new[] { "MyApp.Web.Controllers" } }); LowercaseRoute inherits from Route and just makes all paths lowercase. I also

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

MVC 3 use different controllers based on request parameters

╄→гoц情女王★ 提交于 2019-12-19 04:59:50
问题 I've been scouring the web for a solution for this the past couple days and I'm not finding much. Hopefully I'm not using the right terminology and it's an easy thing to do. I would like to use a path like: /{projectId} And have a place somewhere early on in the life-cycle where I have access to the route value dictionary that I can query a database or a session object to get the controller name to use for this request. Then be able to specify the controller to use route.Values["controller"]

MVC 3 use different controllers based on request parameters

ぐ巨炮叔叔 提交于 2019-12-19 04:59:06
问题 I've been scouring the web for a solution for this the past couple days and I'm not finding much. Hopefully I'm not using the right terminology and it's an easy thing to do. I would like to use a path like: /{projectId} And have a place somewhere early on in the life-cycle where I have access to the route value dictionary that I can query a database or a session object to get the controller name to use for this request. Then be able to specify the controller to use route.Values["controller"]

ASP.NET MVC routing and areas

末鹿安然 提交于 2019-12-18 12:21:48
问题 I am messing around with ASP.NET MVC 2 Preview 2 and am trying to figure out how routing works with areas and such. In a single project implementation of areas, I want an area named "admin". I am trying to be able to have urls like this: (root)/admin/apples/search (root)/admin/apples/edit/3 (root)/admin/apples/add (root)/admin/oranges/search (root)/admin/oranges/edit/5 (root)/admin/oranges/add (root)/admin I have the area created. I have the controllers created with their respective views,