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.
Related
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.
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>
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
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.
When I install package Microsoft.Web.Helpers I get next warning txt file (after installing):
If the package is installed in an ASP.NET MVC 3 site, the site will not work.
If you’ve already installed the package into an MVC 3 application, uninstall it.
If the MVC 3 site does not work even after you have uninstalled the package, you might need to reinstall the ASP.NET MVC 3 packages as well.
I can use Microsoft.Web.Helpers in controller class but cant in the view (#using Microsoft.Web.Helpers not found).
I trying do next: Using ReCaptcha with MVC3 and razor? ReCaptcha and MVC3, problems getting Microsoft.Web.Helpers working .But it doesnt help.What I missed?
You're missing the namespace in Views\Web.config (not the app root web.config).
<system.web.webPages.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<pages pageBaseType="System.Web.Mvc.WebViewPage">
<namespaces>
<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" />
</namespaces>
</pages>