62,046
社区成员
发帖
与我相关
我的任务
分享
public ActionResult Edit(int id)
{
这里需要提交employee
和list<employeetype>
}
如果不封装成一个对象可以在view中显示2个值么
在view中提交后怎么在
[HttpPost]
public ActionResult Edit(int id, Employee obj)
{
这里获得提交的employeetype值
}
public ActionResult Edit(int id)
{
Employee eObj = EmployeeService.GetSObj.SelectById(id);
if (eObj != null)
{
ViewBag.list = EmployeeTypeService.GetSObj.Select()
.Select(c =>
new SelectListItem{
Text=c.Name,
Value=c.Id.ToString()
});
return View(eObj);
}
else
ModelState.AddModelError("", "该记录无效。");
return RedirectToAction("List");
}
[HttpPost]
public ActionResult Edit(int id, Employee obj, string select)
{
NotNullObj(obj);
if (ViewBag.TypeList!=null)
{
}
try
{
EmployeeService.GetSObj.Update(obj);
// TODO: Add update logic here
return RedirectToAction("List");
}
catch
{
return View();
}
}
视图
@model AlinqCoreProject.Model.Employee
@{
ViewBag.Title = "Edit";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>
Edit</h2>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
@using (Html.BeginForm())
{
@Html.ValidationSummary(true)
<fieldset>
<legend>Employee</legend>
@Html.HiddenFor(model => model.Id)
<div class="editor-label">
@Html.LabelFor(model => model.Code)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Code)
@Html.ValidationMessageFor(model => model.Code)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Name)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Name)
@Html.ValidationMessageFor(model => model.Name)
</div>
<div class="editor-label">
员工类型
</div>
<div class="editor-field">
@Html.DropDownList("select", (IEnumerable<SelectListItem>)ViewBag.list)
@Html.ValidationMessageFor(model => model.Name)
</div>
<p>
<input type="submit" value="Save" />
</p>
</fieldset>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>
这样就行了