ASP.NET MVC 入门8、ModelState与数据验证
2020-12-13 15:49
标签:style class blog code http color ASP.NET MVC 入门8、ModelState与数据验证,搜素材,soscw.com ASP.NET MVC 入门8、ModelState与数据验证 标签:style class blog code http color 原文地址:http://www.cnblogs.com/ybtools/p/3796757.html
try
{
UpdateModel(post, new[] { "Title", "Content", "Slug" });
}
catch
{
return View(post);
}
if (string.IsNullOrEmpty(post.Title))
{
ViewData.ModelState.AddModelError("Title", post.Title, "标题不能为空");
}
if (string.IsNullOrEmpty(post.Content))
{
ViewData.ModelState.AddModelError("Content", post.Content, "内容不能为空");
}
if (!ViewData.ModelState.IsValid)
{
return View(post);
}
文章标题:ASP.NET MVC 入门8、ModelState与数据验证
文章链接:http://soscw.com/essay/35465.html