我有一个带有一个视图的MVC项目,在这个视图中我有一个强烈局部视图,类型为IEnumerable<Raja.DomainClasses.Entities.InvoiceItem>
。我的局部视图内部是Telerik MVC
网格。我使用ajax来保存此网格的每个项目。正如您在此图像中所看到的,用户可以单击“保存”,这会将json的行信息传递给控制器发票中的操作createinvoiceitem
。
如果此保险箱的结果成功,我希望保存的网格行将其颜色更改为绿色,否则我希望此行将其颜色更改为红色,以便用户知道哪一个已保存,哪一个中止了保存。
如何知道此行是否已保存在局部视图中?我在我的控制器中使用了view-bag
,但在部分视图中看不到view bag
,我使用session
但我看不到session
。
这是部分视图中保存按钮的功能
function SaveRow(index) {
alert($("#Invoice_InvoiceNumber").val());
InvoiceItemValidation();
var indexvalue1 = $('#InvoiceItemGrid > table > tbody > tr td').filter(function () {
return $.trim($(this).text()) == index;
}).parent().index();
indexvalue = indexvalue1 + 1;
var invoiceitem;
invoiceitem = ({
InvoiceNumber: $("#Invoice_InvoiceNumber").val(),
SparePartCode: $('#InvoiceItemGrid > table > tbody > tr:nth-child(' + indexvalue + ') td:nth-child(2)').text(),
Title: $('#InvoiceItemGrid > table > tbody > tr:nth-child(' + indexvalue + ') td:nth-child(3)').text(),
SerialNumber: $('#InvoiceItemGrid > table > tbody > tr:nth-child(' + indexvalue + ') td:nth-child(4)').text(),
Project: $('#InvoiceItemGrid > table > tbody > tr:nth-child(' + indexvalue + ') td:nth-child(5) input[type=number]').val(),
PartCount: $('#InvoiceItemGrid > table > tbody > tr:nth-child(' + indexvalue + ') td:nth-child(6) input[type=number]').val(),
Unit: $('#InvoiceItemGrid > table > tbody > tr:nth-child(' + indexvalue + ') td:nth-child(7) input[type=text]').val(),
Descr: $('#InvoiceItemGrid > table > tbody > tr:nth-child(' + indexvalue + ') td:nth-child(8) input[type=text]').val(),
FaultyReason: $('#FaultyResult').val(),
ShamsiPickupDate: $('#date_input_PickupDate').val(),
WagonNumber: $('#InvoiceItem_PartLocation1_WagonNumber').val(),
Train: $('#TrainCode').val(),
MasterApplier: $('#MasterApplier').val(),
Troubleshooter: $('#Troubleshooter').val(),
});
$.ajax({
url: '/Invoice/InvoiceItemCreate',
contentType: 'application/json; charset=utf-8',
type: 'POST',
dataType: 'json',
data: JSON.stringify(invoiceitem)
})
.success(function (result) {
// Display the section contents.
window.location.href = result.Url;
alert('')
});
}
这是createinvoice
操作:
public ActionResult InvoiceItemCreate(InvoiceItemModel invoiceitem)
{
ViewBag.Result ="true";
ViewBag.Aname = "PartialViewInvoiceItem";
ViewBag.Cname = "Invoice";
ViewBag.FaultyResult = _baseDataServise.GetList()
.Where(u => u.BaseDataType1.Title == "نوع خرابی")
.OrderBy(u => u.Title)
.Select(o => new SelectListItem { Text = o.Title, Value = o.Id.ToString() })
.AsEnumerable();
ViewBag.Warehouses = _WarehouseService.GetList()
.OrderBy(o => o.Title)
.Select(o => new SelectListItem { Text = o.Title, Value = o.Id.ToString() })
.AsEnumerable();
DBResult _DBResult = _InvoiceItemService.AddInvoiceItem(invoiceitem);
string ItemName = invoiceitem.InvoiceNumber+"_"+invoiceitem.SparePartCode;
Session["ItemName"]=_DBResult.IsOK;
return View("CreateFaultyInput",new InvoiceVM());
}