【发布时间】:2017-03-19 10:15:27
【问题描述】:
我尝试从 SelectedList 更新表中的一个属性
这是我的模型
public partial class Interwier
{
[Key]
public int Interwier_id { get; set; }
[Display(Name = "ФИО")]
public string FIO { get; set; }
[Display(Name = "Email")]
public string Email { get; set; }
[Display(Name = "Телефон")]
public string Telephone { get; set; }
[Display(Name = "День рождения")]
public System.DateTime Birthday { get; set; }
[Display(Name = "Город")]
public string City { get; set; }
[Display(Name = "Зарплата")]
public string Salary { get; set; }
[Display(Name = "Английский язык")]
public string English { get; set; }
public Nullable<int> VacancyId { get; set; }
public string Status { get; set; }
public virtual Vacancy Vacancy { get; set; }
}
我需要更新Status 属性。
这是控制器中的编辑操作
public ActionResult Edit(int? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
Interwier interwierModel = db.InterwierModels.Find(id);
if (interwierModel == null)
{
return HttpNotFound();
}
return View(interwierModel);
}
// POST: Interwier/Edit/5
// To protect from overposting attacks, please enable the specific properties you want to bind to, for
// more details see http://go.microsoft.com/fwlink/?LinkId=317598.
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit([Bind(Include = "Id,Email,Telephone,Birthday,City,Salary,English,Status")] Interwier interwierModel)
{
if (ModelState.IsValid)
{
db.Entry(interwierModel).State = EntityState.Modified;
db.SaveChanges();
return RedirectToAction("Incoming");
}
return View(interwierModel);
}
这是它在视图上的外观
<div class="form-group" style="padding-left: 515px;">
<div class="col-md-10">
@Html.DropDownListFor(model => model.Status, new[]
{
new SelectListItem() {Text = "Подтвердить", Value = "Одобрено"},
new SelectListItem() {Text = "Отправить в архив", Value = "Архив"},
}, "Статус", new { @class = "form-control" })
</div>
</div>
当我点击提交按钮时出现此错误
我该如何处理?
【问题讨论】:
标签: c# asp.net asp.net-mvc entity-framework asp.net-mvc-4