我不确定如何实现这一点,我在 Controllers 文件夹中有一个 MovieController.cs,在 Models 文件夹中有一个 MovieCreateViewModel.cs。我需要为创建、编辑和删除视图添加验证。
MovieDetailsViewModel.cs
public class MovieDetailsViewModel
{
public int Id { get; set; }
}
然后我有 MovieController.cs
public class MovieController : Controller
{
Connect connection;
MovieCreateViewModel movie;
MovieDetailsViewModel id;
public MovieController()
{
this.connection = new Connect();
this.movie = new MovieCreateViewModel();
this.id = new MovieDetailsViewMode();
}
public ActionResult Edit(MovieDetailsViewModel id)
{
movie = this.connection.MovieContext.Where(m => m.ID == id).SingleOrDefault(); **//I get an error here**
return View(movie);
}
//
// POST: /Movie/Edit/5
[HttpPost]
public ActionResult Edit(MovieCreateViewModel movieedit)
{
try
{
if (ModelState.IsValid)
{
this.connection.MovieContext.AddObject(movieedit);
this.connection.MovieContext.Context.SaveChanges();
return RedirectToAction("Index");
}
}
catch
{
return View(movieedit);
}
}
对于httpPost,我MovieDetailsViewModel id
在参数列表中输入了类型,请问我从哪里开始?
谢谢