.NET MVC Object reference error

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


.NET MVC Object reference error



I have a very simple starter .NET application with this method in my controller:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using SampleMVC.Models;
// For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860

namespace SampleMVC
{
public class TurtleController : Controller
{
// GET: /<controller>/
public IActionResult Index()
{
return View();
}

public IActionResult Detail( int id ) {
var turtle = new TurtleModel{ id = 1, title = "Pink Turtle" };
return View("Detail",turtle);
}
}



My Turtle Model looks like this:


using System;
namespace SampleMVC.Models
{
public class TurtleModel
{
public int id { get; set; }
public string title { get; set; }

}
}



and my view looks like this:


@page
@model SampleMVC.Models.TurtleModel;
@{
<p>tester @Model.title</p>
}



However I'm getting a Null pointer / Object reference error when trying to view the URL /Turtle/Detail/1. Wondering if you can point me in the right direction?


/Turtle/Detail/1









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Makefile test if variable is not empty

Will Oldham

Visual Studio Code: How to configure includePath for better IntelliSense results