I wanted to know what files I need to add to a blank .NET c# Razor project to load my first page up.
I have created a view called Index.cshtml and inside it contains:
@{
ViewBag.Title = "Index";
}
<h2>@ViewBag.Title</h2>
I have created a controller called HomeController.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace My_Website.Models
{
public class HomeController : Controller
{
//
// GET: /Default1/
public ActionResult Index()
{
return View();
}
}
}
When I run this application, I get the following error:
The view 'Index' or its master was not found or no view engine supports the searched locations. The following locations were searched:
~/Views/Home/Index.aspx
~/Views/Home/Index.ascx
~/Views/Shared/Index.aspx
~/Views/Shared/Index.ascx
~/Views/Home/Index.cshtml
~/Views/Home/Index.vbhtml
~/Views/Shared/Index.cshtml
~/Views/Shared/Index.vbhtml
Is there a way to redirect the script to point to Index.cshtml straight within the View folder without having to put in a Home directory to satisfy the default layout?
You can specify the view file path in your action method: