日期:2014-05-20 浏览次数:20753 次
<% using (Html.BeginForm()) { %> <%= Html.ValidationSummary(true, "必要的信息请输入")%> 分类名称:<%=Html.TextBox("typename")%> <%= Html.ValidationMessage("typename")%><br /> 是否可见:<%=Html.CheckBox("isvisible")%><br /> <input type="submit" value="tijiao" /> <%}%>
[AcceptVerbs(HttpVerbs.Post)] public ActionResult typeadd(string typename, bool isvisible) { Dal.typenews tn = new Dal.typenews(); Model.typenews model = new Model.typenews(); if (ModelState.IsValid) { model.typename = Server.HtmlEncode(typename); model.isvisible = isvisible; if (tn.Add(model) > 0) { //添加成功,跳转到列表页 Response.Redirect("typelist"); } } return View(model); }
if (this.IsPost) { TryUpdateModel(user, new string[] {"Email", "Name", "Password", "NickName"}); if (string.IsNullOrEmpty(user.Email)) { ModelState.AddModelError("Email", "请填写邮箱."); } else if (this.UserService.FindByEmail(user.Email) != null) { ModelState.AddModelError("Email", "该邮箱已经被使用."); } if (string.IsNullOrEmpty(user.Name)) { ModelState.AddModelError("Name", "请填写用户名."); } else if (this.UserService.FindByName(user.Name) != null) { ModelState.AddModelError("Name", "该用户名已经被使用."); } ...
------解决方案--------------------
if (ModelState.IsValid) { this.UserService.Save(user); } } return View(user);