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?
Ran into this issue. Can't really take credit but I uninstalled earlier version and reinstalled latest version of Microsoft ASP.NET MVC4 from Nuget and things are working for me. Hope this helps someone else. Tried all the solutions, but this was the only thing that worked. http://forums.asp.net/t/1823940.aspx?MVC4+WebGrid+problem+in+View+Razor+
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, withingcompilation
tags so it will look like:Try to follow the steps below that had been tested before in an
ASP.NET MVC4
project without any problem.1) Open
NuGet Package Manager
inVisual Studio
and search “microsoft-web-helper” and install.2) After installing it open
web.config
in your solution and changeconnectionStringName
parameter forDefaultMembershipProvider
,DefaultRoleProvider
veDefaultSessionProvider
(if you do not, you might encounter 'DefaultConnection' was not found in the applications configuration or the connection string is empty.” error.3) Rebuild your project and then use a smilar definition like below in your razor view.
Note: Change "Title", "Controller" and "Action" names in
Html.ActionLinks
according to your project.View:
Here are the
css
classes below used inRazor
. If you would like to use yourcss
definitions simply change style properties to that of yours (Some properties are optional as the ones in theRazor View
).Hope this helps...