Dear Friends,
I have developed the material request slip in mvc.. when i save the items to grid the header textboxes are cleared. how to retain the values. please help me... Below showdata function give static value its works: for eg. i give "vivek".
public ActionResult ShowData(int page = 1, string sort = "Id", string sortDir = "ASC")
{
const int pageSize = 10;
bool Dir = sortDir.Equals("desc", StringComparison.CurrentCultureIgnoreCase) ? true : false;
var maxId = (db.MRHdr.Select(x => (int?)x.Id).Max() ?? 0) + 1;
var irc = "MRN-" + maxId;
MRHdr mrhdr = new MRHdr() { MRNo = irc, MRDate = DateTime.Now, Remarks="Vivek"};
var student = mobjModel.GetMRDPage(page, pageSize, sort, Dir, mrhdr.MRNo);
var totalRows = mobjModel.CountStudent(mrhdr.MRNo);
var data = new PagedStudentModel()
{
TotalRows = totalRows,
PageSize = pageSize,
VwMatReq = student,
MRHdr = mrhdr
};
return View(data);
}
What I have tried:
$(".save").live("click", function () {
var id = $("#grid tbody tr").length;
var ircode = $("#ItemR_Code_" + id).val();
var icode = $("#Item_Code_" + id).val();
var qtyreq = $("#Qty_Req_" + id).val();
var mrno = $("#MRNo").val();
if (id != "") {
$.ajax({
type: "GET",
contentType: "application/json; charset=utf-8",
url: '@Url.Action("SaveRecord", "MRD")',
data: { "ircode": ircode, "icode": icode, "qtyreq": qtyreq, "mrno": mrno },
dataType: "json",
beforeSend: function () { },
success: function (data) {
if (data.result == true) {
window.location.replace("ShowData");
}
else {
alert('There is some error');
}
}
});
}
});
Controller:
[HttpGet]
public JsonResult SaveRecord(string itemname, string ircode, string icode, int qtyreq, string mrno)
{
bool result = false;
try
{
result = mobjModel.SaveMRDtl(ircode, icode, qtyreq, mrno);
}
catch (Exception ex)
{
}
return Json(new { result }, JsonRequestBehavior.AllowGet);
}