ASP .NET Model

weixin_33859844發表於2017-11-20

Model是全域性變數,一個頁面一個

前臺

@ModelWebApplication1.Models.Movie;
@{
    ViewBag.Title = "ModelTest";
}
 
<h2>ModelTest</h2>
<label>@Model.ID</label>
<label>@Model.Name</label>
<label>@Model.Director</label>

後臺

public ActionResult ModelTest()
{
    Movie movie=newMovie();
    movie.Director = "haha";
    movie.ID = "1";
    movie.Name = "山有虎2333";
    return View(movie);     //這樣塞進去
}

相關文章