Я изучаю C # MVC, используя linq. Сейчас я не знаю, как сохранить обновленные данные в базе данных
Как обновить данные?
public ActionResult Edit(Table_2 emp)
{
List<Table_2> objemp = new List<Table_2>();
using (var dbs = new guruEntities())
{
var name = emp.name;
var dep = emp.dprmt;
var query = from n in dbs.Table_2.Where(n => n.name == name && n.dprmt == dep)
orderby n.id
select n;
dbs.SaveChanges();
}
return RedirectToAction("Index");
}
Вид:
<div class="form-horizontal">
<h4>Table_2</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
@Html.HiddenFor(model => model.id)
<div class="form-group">
@Html.LabelFor(model => model.name, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.name, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.name, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.dprmt, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.dprmt, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.dprmt, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Save" class="btn btn-default" />
</div>
</div>
</div>
Я не знаю, как получить пользовательские данные из текстового поля и сохранить в базе данных