我将信息加载到网格Kendo,用户可以更改多个员工的值,然后单击按钮进行保存更改。我想将信息(列表)返回给控制器进行更新。
型号:
public class AuthorizationModel
{
[Editable(false)]
[Display(Name = "No. Nómina")]
public int idRoster { get; set; }
[Editable(false)]
[Display(Name="Empleado")]
public string employee { get; set; }
[Display(Name = "Estatus")]
public string status { get; set; }
[Display(Name = "Comentarios")]
[DataType(DataType.MultilineText)]
public string comment { get; set; }
..............//property
..............//property
}
控制器:
[HttpGet()]
[Route("Autorizacion")]
[Authorize()]
public ActionResult Authorization()
{
_orderBLL = new OrderBLL();
var models = new List<AuthorizationModel>();
var orders = _orderBLL.GetPendingOrders();
foreach (var order in orders)
{
var model = new AuthorizationModel();
model.idRoster = int.Parse(order.NUMNOM_CTE);
model.employee = order.NOMBREEMPLEADO;
//other properties
if (order.ESTFIN_AUI.ToUpper()== "P")
model.status = "Pendiente";
models.Add(model);
};
return View(models);
}
[HttpPost()]
[Route("Autorizacion")]
public ActionResult Authorization(IEnumerable<AuthorizationModel> model)
{
//do something with the Information
return View();
}
查看:
@model IEnumerable<ElizondoMX.Models.Order.AuthorizationModel>
@using Kendo.Mvc.UI;
@using ElizondoMX.Telerik.Extensions;
@{
Layout = "~/Views/Shared/_Layout.cshtml";
}
@using (Html.BeginForm("Authorization", "Order", FormMethod.Post))
{
<body>
@(Html.Kendo().Grid(Model)
.Name("OrdersGrid")
.Columns(columns =>
{
columns.Bound(c => c.idRoster).Title("No. Nómina");
columns.Bound(c => c.employee).Title("Empleado");
columns.BoundActionLink((item) => item.idOrder, "Detail", "Order", (item) => new { id = item.idOrder });
columns.Bound(c => c.status).Title("Estatus").EditorTemplateName("StatusDropDown");
columns.Bound(c => c.comment).Title("Comentarios");
})
.Excel(excel => excel
.FileName("Elizondo_Pedidos.xlsx")
.Filterable(true)
)
.Editable(editable => editable.Mode(GridEditMode.InCell))
.Selectable(s => s.Enabled(true)
.Type(GridSelectionType.Row)
.Mode(GridSelectionMode.Single))
.ToolBar(toolbar => toolbar.Excel().Text("Exportar a excel"))
.Sortable()
.HtmlAttributes(new { style = "height: auto;margin: 0px;" })
.DataSource(datasource => datasource
.Ajax()
.Events(events => events.Error("error_handler"))
.Model(model=> model.Id(p => p.idRoster))
.Read(read=> read.Action("Authorization", "Order"))
))
<input type="submit" value="Actualizar Estatus" class="btn btn-primary" />
</body>
}
</html>