How to use #Scripts in MVC3 VS10 application - c#

I have a MVC3 application in Visual Studio 2010 . I need to refer the scripts/styles in layout page using following tag
#System.Web.Optimization.Styles.Render("~/Content/css")
#System.Web.Optimization.Scripts.Render("~/Scripts/script")
But I am unable to use like this, since System.web,optimization is not available from _Layout.cshtml( even though the dll is referred in the project).Please refer to below image
how to resolve this?

First install Microsoft.AspNet.Web.Optimization using Package Manager Console using below command.
Install-Package Microsoft.AspNet.Web.Optimization
Next you need to reference the dll System.Web.Optimization.dll in your web project then you can add this namespace #using System.Web.Optimization in your_Layout.cshtml`.
Also make sure System.Web.Optimization.dll is present in bin folder in project.

Install-Package Microsoft.AspNet.Web.Optimization
In the Nuget Package Manager Console.

Related

Visual Studio 2015 enable MVC 4 support

I have an ASP NET MVC 4 project that "works on my machine(old)". When I load a project in a fresh installation of VS 2015(on a new laptop) - a lot of assemblies are missing and when I try to build the project it complains that classes like ActionResult, Controller are missing.
I checked that on the old laptop the missing dependencies are coming from C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 4\Assemblies. On the new laptop I have only the xml descriptors of the packages but not the dlls.
What I have to install to use MVC 4 in Visual Studio 2015?
Edit: missing dependencies are:
System.Web.Helpers
System.Web.Mvc
System.Web.WebPages
System.Web.WebPages.Deployment
System.Web.WebPages.Razor
I Recommend getting them again from Nuget for your ActionResult Issue its Microsoft.AspNet.Mvc which is making issue.
Open Package Manager Console and insert the command below:
Install-Package Microsoft.AspNet.Mvc
Nuget has this feature that allows you to restore all the missing Assemblies which exists in nuget. you can try that out as well.
Anyway for the rest of them install these packages below as well:
Install-Package Microsoft.AspNet.WebHelpers
Install-Package Microsoft.AspNet.WebPages
Install-Package Microsoft.AspNet.Razor
Check if you have install update 3 for VS2015
also check if Microsoft web developer tools are installed correctly
I have had the same issues when using source control or moving projects from one PC to another.
There is a work around that I use quite often and it works.
Go to YourProjectFolder -> packages.
Remove all the folders except for the xml, repositories.xml, file which is the xml config file for packages downloaded from Nuget.
On your solution in Visual Studio Right click and select Enable Nuget Packages Restore.
Then build the application it will re-download all the required packages.
Hope this helps
For Me what solved the issue is to install ASP.NET MVC 4 for Visual Studio 2010 from Microsoft Web Page

Unable to find System.Net.Http in web site project

I am working with a web site project within Visual Studio 2015. I usually work with web applications so this type of project is new to me.
This application consist of ASP.NET pages (aspx and .cs code behind files). I wanted to add some code to one of the code behind files that would make use of the HttpClient library, however I cannot seem to add a reference to System.Net.Http. It is not present in the references. I do see that the project is targeting .NET 4.0. Could that be the issue?
You can use NuGet to install this assembly. Just run it in the Package Manager Console(View -> Other Windows -> Package Manager Console):
Install-Package System.Net.Http
UPDATE
If you use .NET 4.0 then you can't install the latest version of System.Net.Http because it doesn't compatible with that framework. You have to use:
Install-Package Microsoft.Net.Http -Version 2.0.20710

The namespace RDotNet could not be found

I'm trying to use R with C#. I'm using Unity and MonoDevelop on the C# side and I've R version 3.2.1. I've tried my best to follow instructions here: http://jmp75.github.io/rdotnet/getting_started/
But I'm stuck. Here's what I've done
download nuget.exe, put it in a folder already in PATH.
open CMD.exe
run nuget install R.NET.Community
If I try to reinstall R.NET.Community with the same command above, I got the message that it is already installed (which is good I guess).
My question : what now? I tried to run the RDotNet namespace, but it's not recognized. Obviously I need to set up something else, but I do not know where and what. Any lead would be appreciated!
I wouldn't expect just running the nuget install to add a reference into your project - the nuget installer is basically just downloading the package for you.
You could manually add a reference in your project to the relevant assembly file (.dll) that has been downloaded. However, it would be better to use a package manager within MonoDevelop. If you're using MonoDevelop 3.x or 4.5, you should use the NuGet MonoDevelop add-in and use that to manage the NuGet packages for your project. MonoDevelop 5.x has a NuGet package manager built in, apparently.

PagedList package installed, "missing assembly reference" error in controller

I am following the MVC tutorial, I installed PagedList package, and I cannot use the PagedList reference in the controller.
The type or namespace name 'PagedList' could not be found (are you missing a using directive or an assembly reference?).
First sorry for my terrible English. In my case, I use the MVC5 in Visual Studio Community 2015 and I solved the problem this way:
First I delete the cache of Visual Studio and NuGet cache:
Visual studio - go to %LocalAppData% \Microsoft\WebsiteCache and delete all folder.
Nuget - here
After I use the package manager console to remove PagedList.MVC, then remove PagedList and then re-install them again like so:
uninstall-package PagedList.mvc
uninstall-package PagedList
install-package PagedList
install-package PagedList.mvc
I holpe that help
Include
using PagedList;
using PagedList.Mvc;
in the pgm and run
PagedList and PagedList.Mvc are being installed separately.
NuGet console install commands:
Install-Package PagedList
Install-Package PagedList.Mvc
Make sure you've installed both of packages.
Check your references to see if there is a reference to the PagedList assembly.
If there isn't: Try to reinstall the package
If there is a reference: Check if the file actually exists on the location specified.
Reference example http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-29-92/7750.v20SysRefProps.JPG
I use DNN. My problem was the package (DotNetNuke.Core.8.0.1.239) was outdated.
Check in your solution folder if you have the package installed:
..MySolutionFolder\packages\DotNetNuke.Core.8.0.1.239 (your package name)
Right click on Solution, go to Manage Nuget Packages.
Click on Browse, search for DotnetNuke.
Install:
DotNetNuke.Core
DotNetNuke.Web
I had the issue was because I was using another more than one web application and they did not use the same framework version :)

Where can I find System.Web.Helpers, System.Web.WebPages, and System.Web.Razor?

I am following this article on RazorGenerator and it say's that I must add references to:
System.Web.Helpers.dll
System.Web.WebPages.dll
System.Web.Razor.dll
The only one I can see when I do Add Reference is System.Web.Razor, but I don't know where the other ones are.
You will find these assemblies in the Extensions group under Assemblies in Visual Studio 2010, 2012 & 2013 (Reference Manager)
To sum up all of the options for VS 2017, WebHelpers was installed by installing MVC in previous versions of Visual Studio. If you're getting this error, you probably don't have the older versions of VS installed anymore.
So, installing the Microsoft.AspNet.MVC NuGet package will require Microsoft.AspNet.WebPages and Microsoft.AspNet.Razor, and the Microsoft.AspNet.WebPages includes System.Web.Helpers.dll.
If you've got direct references to System.Web.Mvc.dll and you don't want to use NuGet for MVC, you can get the Microsoft.AspNet.WebPages NuGet, or there are some other NuGet packages that only contain System.Web.Helpers.dll, like the microsoft-web-helpers or System-Web-Helpers.dllpackages.
There appear to be 2 versions of System.Web.Helpers.dll, one for .Net 4.0 and one for 4.5. Choosing the correct version of MVC or AspNet.WebPages will ensure you get the right one.
As for VS2017 I didn't find it in "extensions", there's a Nuget package called "microsoft-web-helpers" that seems to be equivalent to System.Web.Helpers.
I had the same problem , first I couldn't find those dlls in the list of .NET components . but later I figured it out that the solution is :
1- first I changed target framework from .NET framework 4 client profile to .NET framework 4.
2- then scroll down the list of .NET components , pass first list of system.web... , scroll down , and find the second list of system.web... at the bottom , they're there .
I hope this could help others
In VS 2010 just right click on project or on reference and click add reference.
On the popup window Select Assemblies - > Extensions -> System.Web.Helpers
Installing ASP.NET MVC3 from here should help.
On VS2017 I installed the NuGet package: Microsoft.AspNet.WebPages
That did the trick.
This particular NuGet package has a habit of losing its references in one of our projects. From time to time I will need to run the following command in the Package Manager Console to restore the references and everything is OK again
Update-Package Microsoft.AspNet.Webpages -reinstall
I had to install RazorGenerator.Templating to get it all to work. From the NuGet console, type:
Install-Package RazorGenerator.Templating
They should be under C:\Program Files\Microsoft ASP.Net (or C:\Program Files (x86)\Microsoft ASP.Net if you're on a 64-bit OS) in a subfolder for MVC3 or WebPages.
The issue is a missing or outdated version of MVC. I was running VS 2015Preview and could resolve the issue by installing the latest version of MVC via NuGet.
Just in case anyone is still coming across this one.
When you install this nuget package Microsoft.AspNet.WebPages they can be find in C:\Program Files (x86)\Microsoft Visual Studio\Shared\Packages\Microsoft.AspNet.WebPages.x.x.x\lib\net45

Categories

Resources