asp.net-mvc-areas

Why doesn't the compiler find my razor helpers in an Orchard theme?

牧云@^-^@ 提交于 2019-12-11 03:23:45
问题 I would like to share among views the logic for creating an img tag from a mediaPart. I have already created the following razor helper method: @helper CreateImgFromMediaPart(dynamic mediaPart, int width = 150) { var imgSrc = mediaPart != null ? mediaPart.MediaUrl : string.Empty; var imgAlt = mediaPart != null ? mediaPart.AlternateText : string.Empty; <img alt="@imgAlt" src="@imgSrc" /> } I have tried this by creating an App_Code folder, putting into it a MyHelpers.cshtml file, and putting in

MVC5 Area not working

核能气质少年 提交于 2019-12-10 17:13:21
问题 I have two Areas in my MVC 5 app that are not working properly. When I use the following Link http://localhost:45970/Admin/Admin the app loads the proper index.cshtml whicxh is located at /Areas/Admin/Views/Admin/Index.cshtml however when I try to load http://localhost:45970/Admin it tries to load the Index.cshtml file from /Views/Admin/Index.cshtml . All the search results say I am doing the correct thing. I have even loaded a sample API project to look at the help area in it to make sure I

MVC controller.Execute with areas

放肆的年华 提交于 2019-12-10 14:54:36
问题 I've a site in MVC4 using areas. In some area (lets call it Area), I have a controller (Controller) with this actions: public ActionResult Index() { return View(); } public ActionResult OtherAction() { return View("Index"); } This works great if I make a simple redirect to Area/Controller/OtherAction like this: return RedirectToAction("OtherAction", "Controller", new { area = "Area" }); But I need (check here why) to make a redirect like this: RouteData routeData = new RouteData(); routeData

asp.net mvc area default page

吃可爱长大的小学妹 提交于 2019-12-10 12:39:07
问题 I have a MVC 2 site with an area, let's say the area name is {Admin} The areas and the site works fine. What I am trying to do is to have different default page for the area. When I am calling http://webSiteName works with no problem but for http://webSiteName/Admin I am getting the error The resource cannot be found I tried it out the solutions from ASP.NET MVC 2 RC 2 returns Area-specific controller when no area specified but with no luck. I tried also routes.MapRoute( "Admin", "{controller

How to set Area view as home page in ASP.NET MVC?

谁说胖子不能爱 提交于 2019-12-09 13:31:51
问题 How to setup route for a view to be as home page of a domain in ASP.NET MVC application which contains Areas. I need a view of a particular area to be home page. How could this be done? I tried using the following code without any success. public static void RegisterRoutes(RouteCollection routes) { routes.MapRoute( name: "Home", url: "", defaults: new { controller = "Home", action = "Index" }, namespaces: new string[] { "WebApp.Areas.UI.Controllers" } ); } 回答1: In the Area folder there is a

Custom errors override in ASP.NET MVC area

旧巷老猫 提交于 2019-12-09 13:07:17
问题 I would like to have custom error pages unique to an MVC area. Unfortunately, it appears that the Web.config override system doesn't take the MVC folder structure into account. If I want to override an area called "mobile", I have to create a root project folder (in with Views and Controllers) named "mobile" and put the Web.config in there with the new customErrors element. Is there some better way to do this so that I don't have to create a root folder for any overrides? 回答1: I've been

Reuse an MVC area in multiple MVC applications?

自闭症网瘾萝莉.ら 提交于 2019-12-09 12:20:10
问题 I have some common web pages that will be in multiple MVC applications. For those pages I'd like to reuse the same source code (controllers + views) between the different MVC web sites. What is the best way to go about doing this? ASP.NET MVC areas seem like one possibility but they just a sub directory of the website project. Is it possible to reuse an MVC area in multiple MVC applications? 回答1: You could embed views into assemblies and implement a custom VirtualPathProvider. 回答2: Look at

Controller with same name as an area - Asp.Net MVC4

蹲街弑〆低调 提交于 2019-12-09 12:06:14
问题 I have a Contacts controller in the main/top area, and I have an area named "Contacts". I get POST 404s to the Contacts controller if I register my areas before I register my top-level routes: protected void Application_Start() { AreaRegistration.RegisterAllAreas(); ModelBinders.Binders.DefaultBinder = new NullStringBinder(); RouteConfig.RegisterRoutes(RouteTable.Routes); } And, if I register my areas after my routes, my 404s to the Contacts controller goes away, but my routes to the Contacts

Set default area - Avoiding `, new {area = “”}` on each link on the site

拟墨画扇 提交于 2019-12-09 06:05:48
问题 This code is inside the master page: <li><a href="<%=Url.Action("Action", "Controller") %>">Main site link</a></li> <li><a href="<%=Url.Action("AreaAction", "AreaController", new {area = "Area"}) %>">Area link</a></li> All the links works good till I'm going to the Area Link . When I go there all the routes of the main area don't work. To fix that I can use this: <li><a href="<%=Url.Action("Action", "Controller", new {area = ""}) %>">Main site link</a></li> My question is, is there a way to

Getting System.Web.Optimization to work in a razor view within a class library

好久不见. 提交于 2019-12-08 18:27:50
问题 I'm building a modular MVC4 app, where each module (=area) is a class library. Models and controllers compile into the .dll, the views get copied into the appropriate folder. At runtime, everything works fine. At design time there is one annoying problem left: When editing a razor view within a class library, Visual Studio doesn't recognize the System.Web.Optimization Namespace. The name "Styles" does not exist in the current context. The name "Scripts" does not exist in the current context.