Ambiguous reference between 'System.Web.WebPages.Scripts' and 'System.Web.Optimization.Scripts' - asp.net-mvc

This may be a similar question, but since the other is not answered I thought I'd ask here. I have a mvc 4 application works fine on my local but when I deployed to my web host I got the following error
ambiguous reference between 'System.Web.WebPages.Scripts' and 'System.Web.Optimization.Scripts'
on every #Scripts.Render("")
Though #Styles.Render("") is fine.
What's the easiest fix for this, I should not need to append "System.Web.Optimization" in front of every #Scripts.
Thanks!
Edit: I tried commenting out System.Web.WebPages in my web.config, still not working, here is my web.config
<pages>
<namespaces>
<add namespace="System.Web.Helpers" />
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Optimization" />
<add namespace="System.Web.Routing" />
<!--<add namespace="System.Web.WebPages" />-->
</namespaces>
</pages>

This problem has been resolved by the web host by doing the following:
Removed MVC 4 reference from GAC (since it is meant to be bin deployed) and also re-installed ASP.NET Web Pages 2.
Basically System.Web.WebPages.Scripts is not in WebPages namespace anymore for webpages2, reinstalling it seems to have helped.
Hope this can help others.
Ray.

Related

Razor page does not contain definintion of Html helper class

I am currently working on an MVC project. The project is working fine on another colleagues machine but I am having trouble with this project. It constantly gives errors with Html helper classes.
"System.Web.WebPages.HtmlHelper does not contain a definition for 'TextboxFor' does not contain definition and no extension method 'TextBoxFor' accepting argument of type System.Web.WebPages.HtmlHelper could be found."
I have googled this problem but have not found any useful solution.
Here are some steps that I tried to solve this problem.
Clean solution and rebuild it.
removed bin and obj folder and rebuild the solution.
checked references in web.config files (both)
Added refrences in web.config like System.Web.Mvc etc..
Copied packages from other colleagues' machine.
Note: I am using visual studio 2013 with MVC 5
Sounds like you're missing the following in the Web.Config in the views folder:
/Views/Web.Config
<?xml version="1.0"?>
<configuration>
<system.web.webPages.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<pages pageBaseType="System.Web.Mvc.WebViewPage"> // <-- this line and contents are important
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
</namespaces>
</pages>
</system.web.webPages.razor>
Views typically derive from System.Web.Mvc.WebViewPage which is configured in the web.config. Make sure the version above matches the version you need.

Problems with Resharper? VS 2015 and MVC

I got VS 2015 and MVC, i get this red stuff in several projects. What can be the cause. Views is the only problem, works fine in code behind.
add below in web.config(Inside View folder web.config as well outside web.config)
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
</namespaces>

MVC Helper #Html.LabelFor not showing up?

Am I missing a reference or something?
I have a reference to System.Web.Mvc 4.0x
But whenever I try this
#Html.LabelFor(x=>Model.yadda, new {id="_lblYadda"});
I get nothing I can't even get it to compile. I only have a reference to
#Html.Label("Yadda", "Yadda yadda");
I spent like 5 minutes looking, I know it's simple so.. help please!
WebConfig namespaces are:
<namespaces>
<add namespace="System.Web.Helpers" />
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Optimization" />
<add namespace="System.Web.Routing" />
<add namespace="System.Web.WebPages" />
</namespaces>
Found my issue:
I noticed that the project that works references System.Web.Mvc.Html and the one that I'm using for #Html.Label() references System.Web.WebPages.dll
I removed the reference to System.Web.WebPages.dll and now it works with all the extensions.
System.Web.WebPages.dll is crap... The End... THanks

Razor Compiler Warning/Errors - ASP.NET MVC 4

I have an issue which seems to have been reported here:
Need razor view engine auto-complete to work in a class library?
My issue is the following Warning:
G:\Accountable\Accountable\Views\LedgerUser\EditorTemplates\LedgerServiceViewModel.cshtml:
ASP.NET runtime error: There is no build provider registered for the
extension '.cshtml'. You can register one in the
section in machine.config or web.config.
Make sure is has a BuildProviderAppliesToAttribute attribute which
includes the value 'Web' or 'All'.
This issue is apparent in all my views. Sample images below.
Now all posts and references online that I have found are referencing to adding various Web.config (as mentioned in the previous post) options, but this doesn't seem to work, as I have these configurations defaulted in the project. Here are my Web Configs:
Main Web.config
View root Web Config
I think this issue maybe while im also getting the following compiler errors on the Views:
The name 'Html' does not exist in the current context
What am I doing wrong?
Arrrgghhh i had missed the following from the ROOT Web.config:
<compilation debug="true" targetFramework="4.0">
<!-- New -->
<assemblies>
<add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</assemblies>
</compilation>
This allowed fixed the error and allowed me to use Intellisense within the View.
Putting back the following lines in root Web.config fixed:
<system.web>
<pages>
<namespaces>
<add namespace="System.Web.Helpers" />
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Optimization" />
<add namespace="System.Web.Routing" />
<add namespace="System.Web.WebPages" />
</namespaces>
</pages>
</system.web>
I got it working by simply unloading and reloading the project. All the namespaces above were already there in the root web.config and I was still getting this issue.
Removing the temporary asp.net framework files works for me.
Stop IIS and remove everything under this folder:
C:\Windows\Microsoft.NET\Framework64\[framework version]\Temporary ASP.NET Files
Then restart IIS. Bam!
I tried by restart IIS, removed Temporary ASP.NET Files and changing the compilation tag in the web config file. None of them work for me.
I fixed the issue by removing and adding System.Web.MVC to the project.
In my case Razor syntax are Highlighted in red.

Convert existing asp.net web application to MVC3

I have an existing asp.net web application which I need to convert to mvc3.
As soon as I add the below my project's web.config, the project stops working I am using IIS 5. I guess I have missed something in IIS, please advise
<pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID">
<namespaces>
<add namespace="System.Web.Helpers" />
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="System.Web.WebPages" />
</namespaces>
</pages>
First confirm if any MVC3 project works with IIS5 the way you have it configured, you may need to setup the wildcard rule and uncheck verify if file exsists. Once you have done this what I do is just create a new MVC3 project that is empty and move over my stuff from the old project to the new project. That is the least hassel free way of doing it. Keep the namespace of the solution the same so you don't have to deal with namespace mismatch issues.

Resources