0
我有一個帶有索引和詳細視圖的MVC應用程序。索引顯示_peticiones列表項。我想從Detail視圖更新這個列表。其他職位的更新列表
詳情查看
@using (Html.BeginForm())
{
<div class="form-group">
<label for="id">Id:</label>
@Html.TextBoxFor(m => m.Id, new { @id = "id", @class = "form-control", @readonly = "readonly" })
</div>
<div class="form-group">
<label for="nombre">Nombre:</label>
@Html.TextBoxFor(m => m.Nombre, new { @nombre = "nombre", @class = "form-control"})
</div>
<div class="form-group">
<label for="desc">Descripcion:</label>
@Html.TextBoxFor(m => m.Desc, new { @dec = "desc", @class = "form-control"})
</div>
<div class="form-group">
<label for="fecha">Fecha:</label>
@Html.TextBoxFor(m => m.Fecha, new { @fecha = "fecha", @class = "form-control"})
</div>
<div class="form-group">
<label for="activo">Activo:</label>
@Html.TextBoxFor(m => m.Activo, new { @activo= "activo", @class = "form-control" })
</div>
<div class="container-fluid">
<div class="col-md-12 text-right">
<input type="submit" value="Guardar" class="btn btn-primary" />
</div>
</div>
}
控制器(更新方法具有 「ID」 爲參數,我無法使用對象像的參數)
public ActionResult Detail(Peticion peticion)
{
if (ModelState.IsValid)
{
var id = peticion.Id;
_peticionService.Update(id);
return RedirectToAction("Index");
}
return View();
}
類PeticionService
public bool Update(int id)
{
if (id > 0)
{
var peticionOld = _peticiones.FirstOrDefault(u => u.Id == id);
if (peticionOld != null)
{
//How to update item list??
return true;
}
}
return false;
}
如何更新列表從「PeticionService」類只有ID?
_peticiones來自Update語句?你想在列表中更新什麼?我假設的Peticion領域? – Wheels73
_peticiones是在PeticionesService類中創建的列表。這是我試圖更新的列表。 – Gelabert
對不起,我的意思是在Update語句的上下文中。 MVC是無狀態的。當您發佈到「更新」時,_peticiones如何設置? – Wheels73