Mvc 4 Portable Areas css

时间:2015-06-01 06:46:58

标签: asp.net-mvc-4 mvccontrib

我遵循了以下示例(http://elegantcode.com/2012/04/06/mvc-portable-areas/)但我的css尚未找到。

这是我的区域注册:

public class AdminAreaRegistration : PortableAreaRegistration
{
    public override string AreaName
    {
        get
        {
            return "Admin";
        }
    }

    private void RegisterRoutes(AreaRegistrationContext context)
    {
        context.MapRoute(
            AreaName + "_scripts",
            base.AreaRoutePrefix + "/Scripts/{resourceName}",
            new { controller = "EmbeddedResource", action = "Index", resourcePath = "scripts" },
            new[] { "MvcContrib.PortableAreas" }
        );

        context.MapRoute(
            AreaName + "_content",
            base.AreaRoutePrefix + "/Content/{resourceName}",
            new { controller = "EmbeddedResource", action = "Index", resourcePath = "content" },
            new[] { "MvcContrib.PortableAreas" }
        );

        context.MapRoute(
            AreaName + "_images",
            base.AreaRoutePrefix + "/images/{resourceName}",
            new { controller = "EmbeddedResource", action = "Index", resourcePath = "images" },
            new[] { "MvcContrib.PortableAreas" }
        );

        context.MapRoute(
            AreaName + "_default",
            base.AreaRoutePrefix + "/{controller}/{action}/{id}",
            new { action = "Index", id = UrlParameter.Optional },
            new[] { "ScenicTours.SecurityAdmin.UI.www.Areas.SecurityAdmin.Controllers", "MvcContrib" }
        );
    }

    public override void RegisterArea(AreaRegistrationContext context, IApplicationBus bus)
    {
        RegisterRoutes(context);
        RegisterAreaEmbeddedResources();
    }
}

这是我的区域_Layout.cshtml:     @model动态

@{
    Layout = "~/Views/Shared/_Layout.cshtml";
}


@section HeaderScript {
    <script src="@Url.Content("~/Admin/Scripts/Admin.js")"></script>
    @RenderSection("HeaderScript", required: false)
}

@section HeaderStyles {
    <link href="@Url.Content("~/Admin/Content/Admin.css")" rel="stylesheet" type="text/css" />
    <link href="@Url.Content("~/Admin/Content/AdminStyle.css")" rel="stylesheet" type="text/css" />
}

@section SubMenuItems {
    <li>
        @Html.ActionLink("Users", "Users", "Main", new { area = "Admin" }, null)
    </li>
    <li>
        @Html.ActionLink("Roles", "Roles", "Main", new { area = "Admin" }, null)
    </li>
}


<h5>This is _Layout.cshtml in the Admin area</h5>
@RenderBody()

我可以导航到ok区域中的任何控制器操作,但每次有一个css或js的嵌入资源时我都会收到404错误。

注意: 我可以证实: 1.将每个css和js设置为一个enbeded资源。 2.区域和主要项目都是使用.net 4.5

的mvc 4项目

有人可以帮忙吗?

0 个答案:

没有答案