我在 MVC 2 应用程序中使用便携式区域。我在文件夹 /Scripts/ViewModels/ViewModel.js 中有一个 javascript 文件,但是当我尝试访问它时,我收到一个 404 错误,因为找不到。便携式区域的注册如下所示:
private void RegisterRoutes(AreaRegistrationContext context)
{
context.MapRoute(
AreaName + "_resources",
base.AreaRoutePrefix + "/resource/{resourceName}",
new { controller = "EmbeddedResource", action = "Index"},
new[] { "MvcContrib.PortableAreas" }
);
context.MapRoute(
AreaName + "_scripts",
base.AreaRoutePrefix + "/Scripts/{resourceName}",
new { controller = "EmbeddedResource", action = "Index", resourcePath = "scripts" },
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[] { "PortableAreaDemo.PortableAreas.Areas.Demo.Controllers", "MvcContrib" }
);
}
在视图模板中,我尝试包含脚本文件
<script src="@Url.Content("~/Demo/Scripts/ViewModels/ViewModel.js")"></script>
并获得以下 url /Demo/Scripts/ViewModels/ViewModel.js
,但该文件不可访问。我只能访问作为 Scripts 文件夹的直接子级的脚本文件。