I am able to use WebGrid in any controller like:
var grid = new WebGrid(emailsFetched, columnNames);
I had to add a reference in my ASP.NET MVC project to System.Web.Helpers
for this.
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
but this throws another issue:
There is no build provider registered for the extension '.cshtml'. You can register one in the <compilation><buildProviders> section in the machine.config or web.config. Make sure is has a BuildProviderAppliesToAttribute attribute which includes the value 'Web' or 'All'.
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:
<assemblies>
<add assembly="System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</assemblies>
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>