[转]教你一招 - 如何给nopcommerce增加一个类似admin的area

本文转自:http://www.cnblogs.com/wucf2004/p/nopcommerce-area.html

asp.net mvc里面的area是什么,点击这里查看

如果在nopcommerce里面加入类似admin的area,步骤如下:

1、新建一个mvc空项目MvcApplication1,位置放在\Nop.Web下面,添加一个类MvcApplicationAreaRegistration.cs用于注册area,内容如下:

[转]教你一招 - 如何给nopcommerce增加一个类似admin的area
using System.Web.Mvc;

namespace MvcApplication1
{
public class MvcApplicationAreaRegistration : AreaRegistration
{
public override string AreaName
{
get
{
return "MvcApplication1";
}
} public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"MvcApplication1_default",
"MvcApplication1/{controller}/{action}/{id}",
new { controller = "Home", action = "Index", area = "MvcApplication1", id = "" },
new[] { "MvcApplication1.Controllers" }
);
}
}
}
[转]教你一招 - 如何给nopcommerce增加一个类似admin的area

2、修改MvcApplication1/Views/_ViewStart.cshtml,内容如下:

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

如果不修改的话会提示找不到view的。 3、添加一个HomeController和对应的视图,这里不再详细说明。 4、修改MvcApplication1输出路径,改为:..\bin\,要不然是找不到dll的。 5、删除Global.asax文件,删除web.config里面不需要的内容,可参考admin下面的config文件。 6、最后关键一步,修改Nop.Web.Framework\Themes\ThemeableVirtualPathProviderViewEngine.cs的方法GetPath,添加如下内容:

[转]教你一招 - 如何给nopcommerce增加一个类似admin的area
if (!string.IsNullOrEmpty(areaName) && areaName.Equals("mvcApplication1", StringComparison.InvariantCultureIgnoreCase))
{
//admin area does not support mobile devices
if (mobile)
{
searchedLocations = new string[0];
return string.Empty;
}
var newLocations = areaLocations.ToList();
newLocations.Insert(0, "~/MvcApplication1//Views/{1}/{0}.cshtml");
newLocations.Insert(0, "~/MvcApplication1//Views/{1}/{0}.vbhtml");
newLocations.Insert(0, "~/MvcApplication1//Views/Shared/{0}.cshtml");
newLocations.Insert(0, "~/MvcApplication1//Views/Shared/{0}.vbhtml");
areaLocations = newLocations.ToArray();
}
[转]教你一招 - 如何给nopcommerce增加一个类似admin的area

重新编译测试一下吧,地址http://localhost:2619/MvcApplication1/Home。

分享是一种美。版权所有,转载请注明出处 http://www.nopchina.net/

 
 
上一篇:javascript window.onload 加载多个函数的方法


下一篇:[转]nopCommerce Widgets and How to Create One