如何在CSHTML视图中使用的WebGrid? [英] How to use WebGrid in a cshtml view?
问题描述
我可以使用<一个href=\"http://msdn.microsoft.com/en-us/library/system.web.helpers.webgrid%28v=vs.99%29.aspx\">WebGrid在任何控制器,如:
I am able to use WebGrid in any controller like:
VAR电网=新的WebGrid(emailsFetched,COLUMNNAMES);
我必须在我的ASP.NET MVC项目添加引用 System.Web.Helpers
这一点。
I had to add a reference in my ASP.NET MVC project to System.Web.Helpers
for this.
但是,当我尝试使用查看本网站网直接(以避免在控制器的实例和其他设置),它说:类型或命名空间'的WebGrid不能找到
。好吧,我想在这里补充一个也参照:
But when I try to use this web grid in view directly (to avoid instantiation and other settings in controller) it says: The type or namespace 'WebGrid' cannot be found
. Ok, I tried to add a reference here too:
@using System.Web.Helpers
但是,这将引发另一个问题:
@using System.Web.Helpers
but this throws another issue:
没有为扩展没有注册生成提供.cshtml。你可以注册一个在&lt;&编译GT;&LT; buildProviders&GT;在machine.config或web.config中一节。请确保有一个BuildProviderAppliesToAttribute属性,其中包括价值网络或所有。
这是pretty奇怪......我见过净它正在使用的WebGrid,不具备申报在CSHTML认为什么足够的例子...
This is pretty strange... I've seen enough example on net which are using WebGrid and don't have to declare anything in the cshtml view...
你能告诉我怎么解决这个问题?或者为什么我会遇到这样很丑陋的问题?
Can you please tell me how to solve this? Or why I encounter this very ugly issue?
推荐答案
最后,我已经能够注意到这个:
Finally I've been able to notice that this:
&LT;&集会GT;
&LT;添加组件=System.Web.Helpers,版本= 1.0.0.0,文化=中性公钥= 31BF3856AD364E35/&GT;
&LT; /组件&GT;
在web配置以复加,在的System.Web
部分,withing 编译
标记,这样它看起来这样的:
has to be added in web config, under system.web
section, withing compilation
tags so it will look like:
<system.web>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</assemblies>
</compilation>
</system.web>
这篇关于如何在CSHTML视图中使用的WebGrid?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!