Click here to Skip to main content
15,883,883 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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".

C#
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:

JavaScript
$(".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:
C#
[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);  
      }
Posted
Updated 20-Nov-16 19:16pm
v3
Comments
Vivek.anand34 19-Nov-16 2:36am    
I have updated my question. above show data function I gave Remarks="Vivek" its executed. but i need what i enter in remarks textbox..
Can't you send the textbox value to ShowData?

In ASP.NET MVC retaining data is very simple;
if you POST a form where controller found some error and revert back the view with input module bound with it, so no worry.


If you do a custom Ajax post, HTML would not be changed, you need to show the Action result on top of the earlier HTML, simple.

If you do it from inline grid editing, following article may help;

Grid inline editing demo
 
Share this answer
 
Comments
Vivek.anand34 21-Nov-16 1:01am    
3 days am trying not resolve this problem.. please anyone help...
am save using javascript and [HTTPGET] in controller.
Vivek.anand34 21-Nov-16 1:05am    
Actually in script window.location.replace("ShowData"); without this line. save but didn't bind in grid. with this line binded. but header textbox cleared.
anup.bhunia 21-Nov-16 1:49am    
Not very clear what you mean by header textbox...you may post some screenshot.
In a separate note, you should not use HTTPGET method for saving data.
Vivek.anand34 21-Nov-16 4:16am    
How to attach file here.. and see above its my save code..
You already have all the data in client side. Just make a html table row and append that to the table.

I don't think you need to call the "ShowData" method.

Update
You can use something like below to append a row to table.
JavaScript
$('#myTable > tbody:last-child').append('<tr><td>Data 1</td><td>Data 2</td></tr>');
 
Share this answer
 
v3
Comments
Vivek.anand34 21-Nov-16 2:33am    
How to append it.. can u sample code..
Check my updated answer.
Vivek.anand34 21-Nov-16 3:16am    
actually the grid values comes from database.. when i click the save button in grid it saved and show in grid.
Then just return those values from the save method itself and append inside success method using those values.
Vivek.anand34 21-Nov-16 4:22am    
above code is my save method code.. how to get values in success method.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900