修改Edit.cshtml上部分字段,點擊保存跳轉到Index.cshtml。
但現在點擊保存,就跳出以下錯誤。
**這是Model **
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Web;
namespace MvcSilverTalent.Models
{
public class RetireeModel
{
[Key]
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
public int RetireNum { get; set; }
[Required]
[DisplayName("單位編號")]
[MaxLength(3)]
public string UnitID { get; set; }
[Required]
[DisplayName("員工編號")]
[MaxLength(6)]
public string EmployeeID { get; set; }
[Required]
[DisplayName("離退休類型")]
public int RetireType { get; set; }
[Required]
[DisplayName("刪除標記")]
public int DeleteFlag { get; set; }
//
// 基本信息
[Required]
[DisplayName("姓名")]
[MaxLength(20)]
public string Name { get; set; }
[Required]
[DisplayName("性別")]
public Boolean Gender { get; set; }
[Required]
[DisplayName("身份證號碼")]
public string IDCardNo { get; set; }
[Required]
[DisplayName("出生年月")]
public DateTime Brityday { get; set; }
[Required]
[DisplayName("民族")]
[MaxLength(30)]
public string Nationality { get; set; }
[Required]
[DisplayName("籍貫")]
[MaxLength(30)]
public string NativePlace { get; set; }
[DisplayName("黨派")]
[MaxLength(30)]
public string Party { get; set; }
[DisplayName("所在黨支部")]
[MaxLength(100)]
public string PartyBranch { get; set; }
[DisplayName("最高學歷")]
[MaxLength(20)]
public string EducationDegree { get; set; }
[Required]
[DisplayName("用戶組")]
public string GroupName { get; set; }
[Required]
[DisplayName("是否參加愛心基金")]
public Boolean HasLoveFund { get; set; }
[DisplayName("享受愛心基金慰問情況")]
public string LoveFundCase { get; set; }
[DisplayName("慰問走訪情況")]
public string VisitCase { get; set; }
//
// 工作信息
[Required]
[DisplayName("參加工作時期")]
public int WorkPeriod { get; set; }
[Required]
[DisplayName("參加工作時間")]
public DateTime WorkTime { get; set; }
[Required]
[DisplayName("退休時間")]
public DateTime RetireTime { get; set; }
[Required]
[DisplayName("工齡")]
public int WorkAge { get; set; }
[Required]
[DisplayName("退休單位")]
[MaxLength(100)]
public string UnitName { get; set; }
[DisplayName("職稱代碼")]
[MaxLength(3)]
public int TitleID { get; set; }
[DisplayName("職稱")]
[MaxLength(30)]
public string Title { get; set; }
[DisplayName("職務")]
[MaxLength(30)]
public string Position { get; set; }
[DisplayName("編制")]
[MaxLength(30)]
public string Formation { get; set; }
//
// 可修改信息
[Required]
[MaxLength(255)]
[DisplayName("近照")]
public string PhotoUrl { get; set; }
[MaxLength(255)]
[DisplayName("特長")]
public string Specialty { get; set; }
[Required]
[MaxLength(255)]
[DisplayName("現住地址")]
public string Address { get; set; }
[MaxLength(30)]
[DisplayName("家庭電話")]
public string HomeTel { get; set; }
[MaxLength(30)]
[DisplayName("手機號碼")]
public string MobileNum { get; set; }
[MaxLength(10)]
[DisplayName("郵政編碼")]
public string ZipCode { get; set; }
[MaxLength(40)]
[DisplayName("郵箱")]
public string Email { get; set; }
public virtual ICollection<EventSignModel> EventSignModels { get; set; }
public virtual ICollection<HealthSignMain> HealthSignMains { get; set; }
}
}
**這是controller **
// GET: /UserInfo/Edit.cshtml
public ActionResult Edit(int RetireNum)
{
RetireeModel RetireeModel = db.RetireeModels.Find(RetireNum);
if (RetireeModel == null)
{
return HttpNotFound();
}
return View(RetireeModel);
}
//
// POST: /UserInfo/Edit.cshtml
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit(RetireeModel RetireeModel)
{
Response.Write("<script>alert('ddddd')</script>");
if (ModelState.IsValid)
{
db.Entry(RetireeModel).State = EntityState.Modified;
db.SaveChanges();
return RedirectToAction("Index");
}
Response.Write("<script>alert('xxxx')</script>");
return View("Index");
}
[DisplayName("職稱代碼")]
[MaxLength(3)]
public int TitleID { get; set; }