0
我已經添加了一個管理區域到我的mvc 4網站,以方便地維護我的網站。當我訪問mywebsite.com/admin/home時,右側的控制器會被調用,但會進入我錯誤的主視圖。區域不使用正確的視圖
所以我一個區域名爲admin,我的主站控制器和視圖是不是在一個地區(我不知道這是否會導致問題)
我的路線:
routes.MapRoute(
name: "Admin_default",
url: "Admin/{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional },
namespaces: new string[] { "Topsite.Areas.Admin.Controllers" }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional },
namespaces: new string[] { "Topsite.Controllers" }
);
注意:我有一個自定義視圖引擎。
視圖引擎:
AreaViewLocationFormats = new[] {
"~/Areas/{2}/Views/%1/{1}/{0}.cshtml",
"~/Areas/{2}/Views/%1/{1}/{0}.vbhtml",
"~/Areas/{2}/Views/%1/Shared/{0}.cshtml",
"~/Areas/{2}/Views/%1/Shared/{0}.vbhtml"
};
AreaMasterLocationFormats = new[] {
"~/Areas/{2}/Views/%1/{1}/{0}.cshtml",
"~/Areas/{2}/Views/%1/{1}/{0}.vbhtml",
"~/Areas/{2}/Views/%1/Shared/{0}.cshtml",
"~/Areas/{2}/Views/%1/Shared/{0}.vbhtml"
};
AreaPartialViewLocationFormats = new[] {
"~/Areas/{2}/Views/%1/{1}/{0}.cshtml",
"~/Areas/{2}/Views/%1/{1}/{0}.vbhtml",
"~/Areas/{2}/Views/%1/Shared/{0}.cshtml",
"~/Areas/{2}/Views/%1/Shared/{0}.vbhtml"
};
ViewLocationFormats = new[] {
"~/Themes/" + Theme + "/Views/{1}/{0}.cshtml",
"~/Themes/" + Theme + "/Views/%1/Shared/{0}.cshtml",
};
MasterLocationFormats = new[] {
"~/Themes/" + Theme + "/Views/%1/{1}/{0}.cshtml",
"~/Themes/" + Theme + "/Views/%1/Shared/{0}.cshtml",
};
PartialViewLocationFormats = new[] {
"~/Themes/" + Theme + "/Views/%1/{1}/{0}.cshtml",
"~/Themes/" + Theme + "/Views/%1/{1}/{0}.vbhtml",
"~/Themes/" + Theme + "/Views/%1/Shared/{0}.cshtml",
"~/Themes/" + Theme + "/Views/%1/Shared/{0}.vbhtml"
};
如果有人能幫我,將是巨大的!
讓我知道你是否需要別的東西。
遺憾的是它不解決問題,我已經添加了該文件,但它轉到了錯誤的viewstart文件。 – Jamie
您是否在Global.asax中註冊了自定義視圖引擎? –
是的,我已經在那裏註冊 – Jamie