Asp.net MVC5 - Object reference not set to an instance of an object.


Asp.net MVC5 - Object reference not set to an instance of an object.



I'm training on Asp.net MVC5. and I did the follow.



Model Name is Movie, with code as below.,


namespace mvc1.Models
{
public class Movie
{
public int Id { get; set; }
public string Name { get; set; }

}



And a Controller with name 'MoviesConroller'. and a using statement "using mvc1.Models".


public ActionResult Random()
{

var movie = new Movie() { Name = "Star Trek!" };
return View();
}



And a View with name Random


@model mvc1.Models.Movie
@{
ViewBag.Title = "Random";
Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>@Model.Name</h2>



and this is the error i get
Error









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

Boo (programming language)

How to make file upload 'Required' in Contact Form 7?