我在MVC应用程序注册页面中有一个单选按钮,文本框,下拉列表,用于保存在I中使用的值,如下所示。(为了检查目的,我同时使用了Formcollection和Employee_Info类对象。但是在调试时当我使用formcollection时,我得到所选的值,但是当Employee_Info对象empObjc
我得到它时null
。为什么会这样。我能做什么。
[HttpPost]
[ActionName("EditEmployeeDetails")]
public ActionResult EditEmployeeDetails_Post(int personid,
Employee_Info empObjc, FormCollection a)
{
if (ModelState.IsValid)
{
TryUpdateModel(empObjc);
int ModifiedBy = Convert.ToInt16(Session["LoginPersonID"]);
empBsnObj.UpdateUserDetailss(personid, empObjc, ModifiedBy);
//empContextObj.Entry(empObjc).State = EntityState.Modified;
return RedirectToAction("DisplayEmployeeList", "Admin");
}
return View();
}
我的观点是
@model EmployeeManagementDAL.Employee_Info
<h2>Edit Details</h2>
@using (Html.BeginForm()) <br/>
{ <br/>
<table><tr><td>Is Indian? <br/> <br/>
</td><td>Yes @Html.RadioButtonFor(x=>x.IsIndian, "Yes")
<br/> <br/> No @Html.RadioButtonFor(x=>x.IsIndian, "No") <br/>}
我修改如下
public ActionResult EditEmployeeDetails_Post(int id) <br/>
{ <br/>
if (ModelState.IsValid) <br/>
{ <br/>
Employee_Info empObjc = new Employee_Info(); <br/>
TryUpdateModel(empObjc); <br/>
int ModifiedBy = Convert.ToInt16(Session["LoginPersonID"]); <br/>
empBsnObj.UpdateUserDetailss(id, empObjc, ModifiedBy); <br/>
return RedirectToAction("DisplayEmployeeList", "Admin"); <br/>
} <br/>
return View(); <br/>
}
答案 0 :(得分:1)
我相信你有model specified for the view.
如果您错过请添加如下
@model Employee_Info
@using (Html.BeginForm("EditEmployeeDetails", "Employee"))
{
<div>
@Html.TextBoxFor(m=>m.FirstName)
</div>
}