Do not see the controller and model - asp.net-mvc

in views/jump/index have problem.
first rows:
#model IEnumerable<WhislaMvc.Areas.Admin.Models.Jump>
#{
ViewBag.Title = "Index";
}
#model and ViewBaf - do not see.
I take error:
compilation Error Compiler Error Message: CS0103: The name 'model'
does not exist in the current context Compiler Error Message: CS0103:
The name 'ViewBug' does not exist in the current context
Update:
I comment model and ViewBag
#Html.ActionLink("Create New", "Create")
Html not have method ActionLink why????

From your question description, it shows that, I think you are using Asp.Net MVC 2 and you just tried to use the functionality of Asp.Net MVC 3.
ViewBag comes with Asp.Net MVC 3 (It's feature of Asp.Mvc 3)
There are few suggestions that you can try to avoid compilation error.
Install Asp.Net MVC 3 (Install .Net Framework 4 prior)
Change your project property. (Right Click Web Project -> click
'Properties' -> Application tab -> Target Framework -> Change to
.NET Framework 4
Check and Change your web.config as below:
<compilation debug="true" targetFramework="4.0">
<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" />
<add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</assemblies>
</compilation>
Hope this helps!

All the problems were with the configuration of Web.Config in Area / Admin / Views
WebConfig I get from Views/Web.Config/ is standart.

Related

MVC 5- Application showing error message for System.Web.WebPages.Html.HtmlHelper for controls like viewbag

I have an existing MVC Project which i have Upgraded to MVC 5 .I have used Visual Studio Package Manager to update existing Packages installed.
'System.Web.WebPages.Html.HtmlHelper' does not contain a definition for 'BeginForm' and no extension method 'BeginForm'
Issue is same for other controls like action links too. I have followed the approach mentioned for Upgrading MVC project and made necessary webconfig amendments. Application is not showing intellisence. errors are thrown if i keep view open. More over if i close the view and build application no errors are thrown without any errors. Run properly.
Do Read the post carefully before marking it for similar existing posts. I have already tried few existing solutions provided on stackoverflow.
I am mentioning few links here
System.Web.Mvc.HtmlHelper' does not contain a definition for 'ActionLink'
stackoverflow.com/questions/12041633/razor-views-not-seeing-system-web-mvc-htmlhelper
http://www.asp.net/mvc/tutorials/mvc-5/how-to-upgrade-an-aspnet-mvc-4-and-web-api-project-to-aspnet-mvc-5-and-web-api-2
Please do guide what exactly i am missing any references???
You should have following assemblies in your web.config file (In your Views folder):
In configSections tag:
<sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
<section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
</sectionGroup>
In system.web.webPages.razor tag:
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.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" />
<add namespace="GildenhuisHoboken2014" />
</namespaces>
</pages>
Ok i have fixed it in appsetting it should have a tag
webpages version should be 3.0.0.0
web page and Razor version should be 3.0 not 3.1
mvc 5.1.0.0
You do need to specify the dependent assemble for older tags
do not use upgrade package command. use Manage NuGet Package Manager Interface as just update required stable versions.
Latest supported version for mvc5 should be used for all the packages in use.

Getting System.Web.Optimization to work in a razor view within a class library

I'm building a modular MVC4 app, where each module (=area) is a class library. Models and controllers compile into the .dll, the views get copied into the appropriate folder. At runtime, everything works fine. At design time there is one annoying problem left: When editing a razor view within a class library, Visual Studio doesn't recognize the System.Web.Optimization Namespace.
The name "Styles" does not exist in the current context.
The name "Scripts" does not exist in the current context.
I tried adding the assembly to the system.web/compilation section in the root and the inner web.config:
<add assembly="System.Web.Optimization, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
I tried it without the specific version, too. Both methods didn't solve the problem, but triggered an asp.net runtime error (visible in the first line of the razor view):
Could not load file or assembly 'System.Web.Optimization, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
The assembly is referenced in the project and 'Copy Local' is set to 'True'. It's also added as a namespace in the razor configuration section.
I suspect it's a general problem i'll encounter with other assemblies in the future.
Edit: I did the general setup to get Intellisense going in a razor view within a class library. Everything works so far, except that VS2010 doesn't recognize the Optimization Namespace.
Add a web.config file to the root of your class library project (the one that contains the Razor views) with the following contents (taken from this blog post):
<configuration>
<configSections>
<sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
<section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
</sectionGroup>
</configSections>
<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>
</system.web.webPages.razor>
<system.web>
<compilation targetFramework="4.0">
<assemblies>
<add assembly="System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</assemblies>
</compilation>
</system.web>
</configuration>
This will trick Visual Studio into thinking that it is a web project and enable Intellisense.
I had this error in pre builded view in asp mvc project
for resolve i've installed Microsoft.Web.Optimization with nuget.
From the Tools menu, select Library Package Manager and then click Package Manager Console. Enter the following command to update Bundling and Minification:
Install-Package Microsoft.Web.Optimization -Pre
some additionals here http://forums.asp.net/t/1812274.aspx/1
#Vladimir , I am using Visual Studio 2013, and had to slightly change your line to:
Install-Package Microsoft.AspNet.Web.Optimization
This fixed it for me.
The following:
Install-Package Microsoft.AspNet.Web.Optimization
works fine for me.
Install-Package Microsoft.AspNet.Web.Optimization -version 1.1.0.0
if your project needs specified version, please add -version... for choosing the true version. It will be helpful for you.

MVC View and the System.Speech.Synthesis namespace

This is very strange. An MVC View refuses to recognize the System.Speech namespace. What's the deal? And is there a work around for this? I have a ViewModel that has the VoiceAge and VoiceGender enum properties from this namespace, but the MVC view isn't playing ball.
Repro
Create a new MVC 3 project
Add the "System.Speech" reference
Try to navigate to the System.Speech namespace in the view
In the Controller it's no problem:
using System.Speech.Synthesis;
using System.Web.Mvc;
namespace MvcApplication6.Controllers
{
public class HomeController : Controller
{
public ActionResult Index()
{
VoiceAge voiceAge = VoiceAge.Adult;
return View();
}
}
}
The View, not so much:
I've even added the namespace to the web.config, no luck:
<pages>
<namespaces>
<add namespace="System.Speech.Synthesis" />
Make sure that the System.Speech assembly is present in the <assemblies> section of your web.config:
<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" />
<add assembly="System.Speech, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</assemblies>
Once it is added there make sure you recompile, close and re-open the .aspx view and then, normally, it should work.

Developing ASP.NET MVC using MonoDevelop on MAC

I am developing a web app using ASP.NET MVC 2.0 in MonoDevelop. I have latest Mono 2.10 and MonoDevelop 2.4.2 and I am running them on Mac.
According to mono’s release notes, it should support ASP.NET MVC 2.0. However, I found MonoDevelop’s project templates still only support ASP.NET MVC 1.0. So I had to create MVC project from MonoDevelop and remove system.web.mvc 1.0.0.0 from reference and add system.web.mvc 2.0.0.0 back in. I can write and compile code OK and MonoDevelop does provide intellisense for methods only exist in MVC 2.0 from both C# and aspx file. However, when I trying to run it from MonoDevelop, I had Compilation error complaining ”<%: Html.LabelFor(model => model.Name) %>” as LabelFor method cannot be recognized .
MonoDevelop uses XSP as its testing web server. I am not sure how it configured as I didn’t install it myself. I think it was installed as part of MonoDevelop. My guess is XSP somehow still uses MVC 1.0 but I can't prove it as I couldn’t even find where it is installed.
Could anyone help me out please?
Update:
I have been suspecting web.config too. Here are how they look like now:
web.config
<configuration>
<system.web>
<compilation defaultLanguage="C#" debug="true">
<assemblies>
<add assembly="System.Web.Mvc, Version=2.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.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</assemblies>
</compilation>
<customErrors mode="RemoteOnly">
</customErrors>
<pages>
<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>
<authorization>
<allow users="*" />
</authorization>
web.config under views
<configuration>
<system.web>
<httpHandlers>
<add path="*" verb="*" type="System.Web.HttpNotFoundHandler" />
</httpHandlers>
<pages validateRequest="false" pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<controls>
<add assembly="System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
namespace="System.Web.Mvc" tagPrefix="mvc" />
</controls>
</pages>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<handlers>
<remove name="BlockViewHandler" />
<add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
</handlers>
</system.webServer>
Setting up an ASP.NET project for ASP.NET MVC requires changing and adding a load of settings in web.config. The project template in MD is for ASP.NET MVC 1.0, not ASP.NET MVC 2, so you're probably missing some of the necessary settings, maybe a namespace import.
I have this running with two of my current projects on MacOS X. There were only three steps I needed to make sure were done, they are as follows:
Upgrade the version on all references in both the inner (views) web config and the outter(app) [you've done this].
Dereference System.Web.MVC 1.0.0.0 & Reference 2.0.0.0 for the project
Ensure you don't have 1.0.0.0 binaries in your bin path, the public key does not change
I've done a downloadable zip file of a project template for Asp.Net MVC 4 which builds and runs on/in Mono/Xamarin Studio/MonoDevelop on Mac & Linux at http://www.cafe-encounter.net/p1319/run-asp-net-mvc4-on-mono-monodevelop-on-mac-the-c-template-project.
I should add that a lot of the issue resolution came from Does the Razor View Engine work for Mono?

WebForms and ASP.NET MVC co-existence

I am trying to make a WebForms project and ASP.NET MVC per this question. One of the things I've done to make that happen is that I added a namespaces node to the WebForms web.config:
<pages styleSheetTheme="Default">
...
<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>
However, when I try to start the project, I get an error stating: "Compiler Error Message: CS0234: The type or namespace name 'Mvc' does not exist in the namespace 'System.Web' (are you missing an assembly reference?)"
I have System.Web.Mvc referenced. What is the issue?
Add System.Web.Mvc in the compilation section,
<compilation debug="true">
<assemblies>
<add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Web.Abstractions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</assemblies>
</compilation>
It's easier to start with an MVC project, and then start adding WebForms pages.
For your error, you will need to add references for the following assemblies:
System.Web.Mvc
System.Web.Routing
System.Web.Abstractions
There will be much more to add in the web.config to get MVC working correctly. To get it all, I'd suggest creating an MVC project, and merging the web.config files.

Resources