Spread for ASP.NET 表格控件 MVC5 教程 - Hello World

发布时间:2015/09/27 00:09 发布者:iceman

返回博客中心

本文通过一个“Hello World”的示例,手把手的说明如何把 Spread ASP.NET 表格控件应用在 ASP.NET MVC 5中。

下面我们分别阐述:

1.创建 MVC5 项目:

image

2.选择 MVC 模板:

image

3.添加 FarPoint.Mvc.Spread.dll 和 FarPoint.Web.Spread.dll 到项目中

4.在 Property 文件夹下 添加 Licenses.licx 文件,并且添加以下信息:

FarPoint.Web.Spread.FpSpread, FarPoint.Web.Spread, Version=8.40.20143.0, Culture=neutral, PublicKeyToken=327c3516b1b18457
FarPoint.Mvc.Spread.FpSpread, FarPoint.Mvc.Spread, Version=8.40.20143.0, Culture=neutral, PublicKeyToken=327c3516b1b18457

 

5.打开 Global.asax.cs,在 Application_Start 方法中添加以下代码:

注意:如果在.NET Framework 4.0或更高版本中使用Spread MVC,需要移除FarPoint.Mvc.Spread.MvcSpreadVirtualPathProvider.AppInitialize(); .

protected void Application_Start()
{
//FarPoint.Mvc.Spread.MvcSpreadVirtualPathProvider.AppInitialize();
AreaRegistration.RegisterAllAreas();
RegisterGlobalFilters(GlobalFilters.Filters);
RegisterRoutes(RouteTable.Routes);
//ModelBinders.Binders.DefaultBinder = ModelBinders.Binders[typeof(FarPoint.Mvc.Spread.FpSpread)];
//ModelBinders.Binders.Add(typeof(FarPoint.Mvc.Spread.FpSpread), new FarPoint.Mvc.Spread.MvcSpreadModelBinder());
}

 

6.声明 Spread MVC 命名空间:

@using FarPoint.Mvc.Spread; 或 <%@ Import Namespace="Farpoint.Mvc.Spread" 
%>

 

7.通过以下代码添加Spread到视图页面中:

@Html.FpSpread("FpSpread1"); 或 <=Html.FpSpread("FpSpread1")>
FpSpread1 ID 必须是唯一的。
 
此时运行MVC项目会出现以下错误:
image
 
如何解决呢?需要修改 FarPoint.Web.Spread.dll 的 CopyLocal 属性为 True:
image 
 
再次运行后我们即可看到效果:
 
image 
 
 
以上即为 Spread for ASP.NET 在 MVC5 的使用方法。
下载Demo:
http://www.grapecity.com.cn/livesamples/temp/SpreadWMVC5.zip
 
了解 Spread 表格控件更多功能请参考:
/developer/spread-aspnet
 
 

关于葡萄城

赋能开发者!葡萄城是专业的集开发工具、商业智能解决方案、低代码开发平台于一身的软件和服务提供商,为超过 75% 的全球财富 500 强企业提供服务。葡萄城专注控件软件领域30年,希望通过模块化的开发控件、灵活的低代码应用开发平台等一系列开发工具、解决方案和服务,帮助开发者快速响应复杂多变的业务需求,最大程度地发挥开发者的才智和潜能,让开发者的 IT 人生更从容更美好。

了解详情,请访问葡萄城官网