作者:葛菁昱 | 来源:互联网 | 2023-09-14 17:57
Iveaddedanadminareatomymvc4websitetoeasilymaintainmywebsite.Whenivisitmywebsite.c
I've added an admin area to my mvc 4 website to easily maintain my website. When i visit mywebsite.com/admin/home the right controller gets called but it goes to my wrong home view.
我在我的mvc 4网站上添加了一个管理区域,以便轻松维护我的网站。当我访问mywebsite.com/admin/home时,正确的控制器被调用,但它会进入我错误的主视图。
So i've one area called admin and my main website controllers and views aren't in an area (i don't know if that can cause problems)
所以我有一个名为admin的区域,我的主要网站控制器和视图不在某个区域(我不知道是否会导致问题)
My routes:
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" }
);
Note: I've a custom view engine.
注意:我有一个自定义视图引擎。
ViewEngine:
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"
};
If someone could help me that would be great!
如果有人可以帮助我那将是伟大的!
Let me know if you need anything else.
需要帮助请叫我。
1 个解决方案