我搜索無法找到答案。'System.NullReferenceException'發生在App_Web_zqz5irkc.dll中,但未在用戶代碼中處理
不能找到哪裏是空以及如何解決它
當我運行隨機視圖有空
@model Vidly.Models.Movie
@{
ViewBag.Title = "Random";
}
<h2>
@Model.Name
</h2>
這可能是空從哪裏來但爲什麼。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Vidly.Models;
namespace Vidly.Controllers
{
public class MovieController : Controller
{
// GET: Movie
public ActionResult Random()
{
var movie = new Movie() { Name = "Shrek!" };
return View();
}
}
}
這是我的新希望那類
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace Vidly.Models
{
public class Movie
{
public int Id { get; set; }
public string Name { get; set; }
}
我解釋好
將模型傳遞給視圖。 '返回查看(電影);' –