Jozef
Jozef

Reputation: 493

MVC4 - after adding new controller, corresponding view is not generated

I started learning Asp.NET MVC and got stuck pretty immediately. According to all materials I have, after I add controller in MVC project (Template - empty MVC controller), corresponding view should be created, too (folder under Views). However, when I do this, nothing happens. Does anybody know what could be the problem? And will this cause me a problems in a long run? I guess I could create those files manually, but still would prefer if they were generated...

My system: Visual Studio Professional 2013, Update 5 Project: new MVC Web Application, template "Internet Application"

Thank you

Upvotes: 0

Views: 1773

Answers (2)

mmushtaq
mmushtaq

Reputation: 3520

Other possible way is to add complete path of the view in your controller method which is returning a view.

 public ActionResult Index()
 {
   return View("~/Views/Home/Index.cshtml");
 }

this method is useful when you have a hierarchy of folders for view files.

Upvotes: 2

Jesse Johnson
Jesse Johnson

Reputation: 1718

Normally views aren't created when a new controller is added. Views can be generated with the following methods:

  1. Simply right click the method name within any controller and select "Add View"
  2. Right click on the controllers folder and select "Scaffold..." which will created a new controller, views and/or DataContext for a specified model.

Upvotes: 1

Related Questions