【发布时间】:2017-12-07 01:18:17
【问题描述】:
我正在使用 2017 VC for mac,xamarian 版本的 vs 没有自动区域映射器。我手动添加了 Areas 文件夹并正确配置了路由,当我将 actionLink 添加到我的 csHTML 主页面时,它会抛出 500 错误并声明。
System.InvalidOperationException
The view 'Billing' or its master was not found or no view engine supports the searched locations. The following locations were searched:
~/Views/BillingMain/Billing.cshtml
~/Views/BillingMain/Billing.vbhtml
~/Views/Shared/Billing.cshtml
~/Views/Shared/Billing.vbhtml
~/Views/BillingMain/Billing.aspx
~/Views/BillingMain/Billing.ascx
~/Views/Shared/Billing.aspx
~/Views/Shared/Billing.ascx
它应该在~/Areas/Billing/Views/BillingMainController.cshtml中搜索
我已经尽一切努力让它工作,但只是一直卡住。
这是我的目录层次结构
Project-
AppStart-
Areas-
Billing-
Invoice-
Controllers-
Scripts-
Views-
Global.asax
我现在只测试计费区域,下面是我的其余代码。
路由配置
using System.Web.Mvc;
using System.Web.Routing;
namespace WORK_GODDAMN
{
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
//AreaRegistration.RegisterAllAreas();
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
//,namespaces: new string[] { "WORK_GODDAMN.Areas.Controllers" }
);
}
}
}
BillingAreaRegistration.cs
using System;
using System.Web.Mvc;
namespace WORK_GODDAMN.Areas.Billing
{
public class BillingAreaRegistration : AreaRegistration
{
public override string AreaName
{
get
{
return "Billing";
}
}
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"Billing_Default",
"Billing/{controller}/{action}/{id}",
new {controller = "BillingMain", action = "Index", id = UrlParameter.Optional }
, namespaces: new string[] { "WORK_GODDAMN.Areas.Billing.Controllers" }
);
}
}
}
全球.asax
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using System.Web.Http;
namespace WORK_GODDAMN
{
public class Global : HttpApplication
{
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
RouteConfig.RegisterRoutes(RouteTable.Routes);
GlobalConfiguration.Configure(WebApiConfig.Register);
}
}
}
main _Layout.cshtml 这是 Action Link 重定向的地方,我认为我可能在这里做错了,但目前我不知道是什么导致了问题。
<!DOCTYPE html>
<html>
@using System.Web.Optimization
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<title>@ViewBag.Title</title>
@Scripts.Render("~/Scripts/modernizr.js")
</head>
<body>
<div>
<div>
<h2>{Demo}- Pluggable Modules</h2>
</div>
<div id="nav">
@Html.ActionLink("Home","Index","Home", new {Area=""}, null)
@Html.ActionLink("Invoice","Index","InvoiceMain", new {Area=""}, null)
@Html.ActionLink("Billing","Index","BillingMain", new {Area=""}, null)
</div>
<hr />
<div>
@RenderBody()
</div>
</div>
@Scripts.Render("~/Scripts/jquery.js")
@RenderSection("Scripts", required: false)
</body>
</html>
【问题讨论】:
-
您要访问的网址是什么?
-
localhost:8080/BillingMain应该路由到Views/Billing/BillingMainController -
你不应该在 url 中有区域名称吗?目前我猜它没有击中区域控制器。试试
Billing/BillingMain -
导致
404not found 错误?我之前尝试过,因为这在逻辑上是它应该映射到的地方,但没有用。我不得不手动创建 Areas 文件夹,因为 VS mac 2017 没有 add->Areas 选项
标签: c# html asp.net-mvc asp.net-mvc-4 razor