0
方案: 假設以下類如何-掌握和詳細MVC 2 + Jdgrid
public class remate
{
public virtual int id { get; set; }
public virtual DateTime fecha { get; set; }
...
public virtual List<detalle_remate> detalle_remate { get; set; }
...
}
和
public class detalle_remate
{
public virtual int id { get; set; }
public virtual remate remate { get; set; }
public virtual cliente cliente_comprador { get; set; }
public virtual cliente cliente_vendedor { get; set; }
...
}
對於類remate的每一行有detalle_remate的n行。 用戶通過首先選擇顧客買方(主)的數目輸入數據,可以是用於相同的買方
detalle_remate的多於一行和該控制器
public class RemateController : Controller
{
private remateRepository Repo = new remateRepository();
private remate entity;
private List<detalle_remate> lineas = new List<detalle_remate>();
public ActionResult Crear()
{
entity = new remate(); //crear nueva instancia
entity.fecha = DateTime.Today;
...
return View(entity);
}
public ActionResult List(string sidx, string sord, int page, int rows)
{
int pageIndex = Convert.ToInt32(page - 1);
int rowIndex = Convert.ToInt32(rows);
var datos = lineas.OrderBy(x => x.id).Skip(pageIndex * rowIndex).Take(rowIndex);
double totalregistros = lineas.Count();
int totalPages = (int)Math.Ceiling((decimal)totalregistros/(decimal)rowIndex);
var data = new
{
total = totalPages,
page = page,
records = totalregistros,
rows = from a in datos
select new
{
cell = new string[] {
a.id.ToString(),
a.cliente_vendedor.razon_social,
...
}
}
};
return Json(data, JsonRequestBehavior.AllowGet);
}
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult ABM(detalle_remate entity, FormCollection formCollection)
{
...
}
}
}
設計視圖CREAR是以下
<% using (Html.BeginForm())
{%>
<%= Html.ValidationSummary(true) %>
<fieldset>
<%=Html.LabelFor(m => m.id) %><%=Html.EditorFor(m => m.id) %>
<%=Html.ValidationMessageFor(m => m.id) %> <br />
<%=Html.LabelFor(m => m.fecha) %><%=Html.EditorFor(m => m.fecha) %>
<%=Html.ValidationMessageFor(m => m.fecha) %><br />
<%=Html.Label("Comprador:") %><%=Html.DropDownList("cliente_comprador", (SelectList)ViewData["listaclientes"])%> <br />
<table id="list" class="scroll" cellpadding="0" cellspacing="0"></table>
<div id="listPager" class="scroll" style="text-align:center;"></div>
<div id="listPsetcols" class="scroll" style="text-align:center;"></div>
<script type="text/javascript">
$(document).ready(function() {
var updateDialog = {
url: '<%= Url.Action("ABM", "Remate") %>'
, closeAfterAdd: true
, closeAfterEdit: true
, modal: true
, onclickSubmit: function(params) {
var ajaxData = {};
var list = $("#list");
var selectedRow = list.getGridParam("selrow");
rowData = list.getRowData(selectedRow);
ajaxData = { id: rowData.id };
return ajaxData;
}
, width: "700"
};
$.jgrid.nav.addtext = "Agregar";
$.jgrid.nav.edittext = "Editar";
$.jgrid.nav.deltext = "Borrar";
$("#list").jqGrid({
url: '<%= Url.Action("List", "Remate") %>',
datatype: 'json',
mtype: 'GET',
colNames: ['Número', 'Vendedor', 'Especie', ...],
colModel: [
{ name: 'id', index: 'id', width: 40, align: 'left', editable: true, editrules: { edithidden: false }, hidedlg: true, hidden: true },
{ name: 'cliente_vendedor', index: 'cliente_vendedor', width: 200, align: 'left', editable: true, edittype: 'select', editoptions: { dataUrl: "/Cliente/ClienteSelect" }, editrules: { required: true }, formoptions: { elmsuffix: ' *'} },
{ name: 'especie', index: 'especie', width: 70, align: 'left', editable: true, edittype: 'select', editoptions: { dataUrl: "/Especie/EspecieSelect" }, editrules: { required: true }, formoptions: { elmsuffix: ' *'} },...
],
pager: $('#listPager'),
rowNum: 20,
rowList: [5, 10, 20],
sortname: 'id',
sortorder: "desc",
viewrecords: true,
imgpath: '/Content/ui-lightness/Images',
width: "850",
height: "250",
ondblClickRow: function(rowid, iRow, iCol, e) {
$("#list").editGridRow(rowid, prmGridDialog);
}
}).navGrid('#listPager',
{
edit: true, add: true, del: true, search: false, refresh: true
},
updateDialog,
updateDialog,
updateDialog
);
});
</script>
<% } %>
</fieldset>
正如你所看到的,應該在信息存儲在jdgrid時發送Comprador。我應該如何添加這些信息? *發送JSON作爲Comprador的收入而不顯示在網格中?
任何人都可以幫助我舉一些例子嗎?