如何在 cshtml 视图中使用 WebGrid? [英] How to use WebGrid in a cshtml view?

查看:20
本文介绍了如何在 cshtml 视图中使用 WebGrid?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用 WebGrid 在任何控制器中,例如:

I am able to use WebGrid in any controller like:

var grid = new 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.

但是当我尝试直接在 view 中使用这个网络网格时(以避免实例化和控制器中的其他设置)它说:找不到类型或命名空间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"注册的构建提供程序.您可以在 <compilation><buildProviders> 中注册一个.machine.config 或 web.config 中的部分.确保具有 BuildProviderAppliesToAttribute 属性,其中包含值Web"或All".

这很奇怪......我在网上看到了足够多的例子,它们使用 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:

<代码><程序集><add assembly="System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/></程序集>

必须添加到 web 配置中,在 system.web 部分下,使用 compilation 标签,所以它看起来像:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆