Can people suggest a good way to add views to a project in Visual Studio? The standard MVC way adds scaffolding (Folders named for controllers) and NuGet packages
(MVC, Razor, WebPages, etc...) I'm stuck copying existing views and renaming, or adding a text file and adding the .cshtml
extension. There must be a way to tell Visual Studio to turn off the scaffolding/NuGet
stuff.
-
Is your question specifically about turning off this Visual Studio behavior? Or is it, in general, about the best ways to add new views in VS, without scaffolding being applied?– Dmytro ShevchenkoOct 20, 2016 at 13:22
-
Both. My ideal solution would be to turn that behavior off, but if it depends on the type of project I create, I am well into a project already and cant start from scratch, so how do I avoid it?– Ethan SchoferOct 20, 2016 at 13:29
-
If you don't have MVC, Razor and other NuGet packages installed, how can are you creating views without VS complaining about missing classes, namespaces, etc.? Have you considered just installing the packages matching the versions used by Sitecore?– Dmytro ShevchenkoOct 20, 2016 at 13:52
-
I am manually adding dll references to ensure I have the correct version for my version of Sitecore. That is, the dlls that come with a vanilla Sitecore install.– Ethan SchoferOct 25, 2016 at 1:03
2 Answers
With MVC 5
, you should have the option to add an MVC 5 View Page
, like so,
Using this option gives you a simple popup to type in a name, then it generates a cshtml
file with no scaffolding.
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title></title>
</head>
<body>
<div>
</div>
</body>
</html>
Alternately, you can select MVC Partial Page which just generates an empty .cshtml file.
MSDN reference: https://www.asp.net/mvc/overview/getting-started/introduction/adding-a-view
-
2Alternatively, choose the
MVC 5 Partial Page (Razor)
option to get a cleaner starting point.– bmyersOct 20, 2016 at 13:49 -
-
1
If you use the default Web Applications with MVC project template, I'm not sure whether you can turn off this behaviour. However, you could potentially use Sitecore Rocks to create the files for you instead.
-
1I find Sitecore Rocks to be excruciatingly slow. I conceptually like what it can do but am way too impatient. Oct 20, 2016 at 13:33