当前位置: 动力学知识库 > 问答 > 编程问答 >

session - How can I get the value from an action of the main view controller to the partial view?

问题描述:

I have an MVC project with one view and inside this view I have a strongly partial view which is of the type IEnumerable<Raja.DomainClasses.Entities.InvoiceItem>. Inside my partial view is a Telerik MVC grid. I use ajax for saving each item of this grid. as you can see in this image the user can click on save and this passes the row info by json to the action createinvoiceitem in the controller invoice.

I want the row of grid that was saved to change its color to green if the result of this safe was successful, otherwise I want this row to change its color to red, so the user knows which one was saved and which one aborted the save.

How can I know if this row was saved in the partial view? I used view-bag in my controller but I can't see view bag in the partial view, I used session but I can't see session.

This is function of save button in my partial view

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('')

});

}

This is the createinvoice action:

 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());

}

分享给朋友:
您可能感兴趣的文章:
随机阅读: