Index.cshtml is nothing but this, which Visual Studio created for me:
@model TestModel
@{
ViewData["Title"] = "Index";
}
<h1>Index</h1>
Trying to view the page gives me an unhandled exception error, and the error is NullReferenceException: Object reference not set to an instance of an object.
I have spent a decent amount of time on Google and even searching StackOverflow for answers, but I can't find anything that addresses exactly this problem. Can anyone help?
Edit: Index.cshtml is located in /Views/Text/Index.cshtml
Text of the controller is:
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
namespace MvcMovie.Controllers
{
public class TestController : Controller
{
[BindProperty]
public string FormInput { get; set; }
[BindProperty]
public string Firstname { get; set; }
[BindProperty]
public string Lastname { get; set; }
public IActionResult Index()
{
ViewData["output"] = Firstname + "<br>" + Lastname;
return View();
}
}
}
I've also added @page
to the top of the cshtml file. I still get a NullReferenceException at ViewData["Title"] = "Index";
. Alexander I read your reply on the other thread and there's not enough context for me to understand it. I am just getting started with MVC and Razor pages having taken over a project that uses both, so it's very possible that I am confusing and/or mixing the two. I'll try and read those docs you linked to when I have the chance.