2
내가ASP.NET MVC ModelState.IsValid 나던 작업
[HttpPost]
public ActionResult Create(Topic topic)
{
if (ModelState.IsValid)
{
topicRepo.Add(topic);
topicRepo.Save();
return RedirectToAction("Details", new { id = topic.ID });
}
return View(topic);
}
을 만들이 컨트롤러의 방법을했습니다이 편집
[HttpPost]
public ActionResult Edit(int id, FormCollection formCollection)
{
Topic topic = topicRepo.getTopic(id);
if (ModelState.IsValid)
{
UpdateModel<Topic>(topic);
topicRepo.Save();
return RedirectToAction("Details", new { id = topic.ID });
}
return View(topic);
}
에 대한 (의 .ascx) . 내가 주제를 만들려고하지만 난 그것을 정상
는 정말 고마워요! –
FYI - ModelState.IsValid가 false 인 경우 UpdateModel이 발생합니다. Throw하지 않으려면 대신 TryUpdateModel을 사용하십시오. – Levi
오류가있는 경우 반환보기 (항목)는 양식의 값 대신 데이터베이스에서 값을 반환합니다. 유효성 검사 오류가 표시되지 않습니다. – jlp