4

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.

4
  • 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? Oct 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? Oct 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? Oct 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. Oct 25, 2016 at 1:03

2 Answers 2

9

With MVC 5, you should have the option to add an MVC 5 View Page, like so,

Add MVC 5 View Page context menu

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

3
  • 2
    Alternatively, choose the MVC 5 Partial Page (Razor) option to get a cleaner starting point.
    – bmyers
    Oct 20, 2016 at 13:49
  • Added to the answer! Oct 20, 2016 at 13:51
  • 1
    WRONG!!! Still adds Nugets. Oct 20, 2016 at 18:14
3

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.

1
  • 1
    I 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.