如何在MVC中回发后保留值 [英] How to retain values after postback in MVC

查看:93
本文介绍了如何在MVC中回发后保留值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的朋友们,



我已经在mvc中开发了材料请求单...当我将项目保存到网格时,标题文本框被清除。如何保留价值观。请帮帮我...在showdata函数下面给出静态值它的作用:例如。我给vivek。



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,
             //  MRDtl = student,
               MRHdr = mrhdr
           };
           return View(data);
       }





我的尝试:





What I have tried:

$(".save").live("click", function () {
       var id = $("#grid tbody tr").length;
      // var itemname = $("#Item_Name_" + id).val();
       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 },    //"itemname": itemname,
               dataType: "json",
               beforeSend: function () { },
               success: function (data) {
                   if (data.result == true) {
                     //  $("#divmsg").html("Record has been saved successfully !!");
                       window.location.replace("ShowData");
                     //  setTimeout(function () { window.location.replace("ShowData"); }, 2000);
                   }
                   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);  
      }

推荐答案

。save)。live( click function (){
var id =
(".save").live("click", function () { var id =


(< span class =code-string> #grid tbody tr)。length;
// var itemname =
("#grid tbody tr").length; // var itemname =


(#Item_Name_+ id).val();
var ircode =
("#Item_Name_" + id).val(); var ircode =


这篇关于如何在MVC中回发后保留值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆