On postback should a TextboxFor send the data back to the action

I built an editable table using HTMLand jquery and it worked brilliantly then we were told that the table also needed to be sortable so a colleague took over and changed some of the code and made the table sortable but it is only now I have noticed since this was done, the table no longer posts back when you press enter after you change any thing to make the change go back to the DB. For the life of me I cannot figure out why.
I put in a bit of $.ajax to post it back to the action and it does post back now but the is no data being posted. I thought when I'm using a TextboxFor it would have happened automatically but I found out I was wrong.
here is some of the code.
part of the table
<td class="edit"; id = "AGENTID">

                        <span class="item-display">@Model.getConfirmationData[idx].AGENT_ID</span>            

                        <span class="item-field">@Html.TextBoxFor(modelItem => Model.getConfirmationData[idx].AGENT_ID, new { @class = "inputID", name="getConfirmationData[" + idx + "].AGENT_ID" })</span>

                    </td>

                    <td  class="edit", id="AGENTNAME">

                        <span class="item-display">@Model.getConfirmationData[idx].AGENT_Name</span>       

                        <span class="item-field">@Html.TextBoxFor(modelItem => Model.getConfirmationData[idx].AGENT_Name, new { @class = "inputname", name="getConfirmationData[" + idx + "].AGENT_Name"})</span> 

                    </td>        

                    <td class="edit"; id = "DBAName";>

                        <span class="item-display">@Model.getConfirmationData[idx].DBA_Name</span>       

                        <span class="item-field">@Html.TextBoxFor(modelItem => Model.getConfirmationData[idx].DBA_Name, new { @class = "inputname", name="getConfirmationData[" + idx + "].DBA_Name" })</span>

                    </td>

Open in new window


also this is the script
 

$(document).ready(
      $(document.documentElement)
        .on("click", "span.item-display", function (event)
        {
          $(this).parent().closest('tr').addClass('blue')
          var originalcontent = $(this).text();
          $(event.currentTarget)
            .hide()
            .next("span.item-field")
            .show()
            .find(":input:first")
            .focus()
            .select();
         })
        .on("keypress", "span.item-field", function (event)
        {                    
          if (event.keypress != 13 && event.which != 13)     
            return;
          event.preventDefault();   
          $.ajax({ type: "POST", url: "/AGENT/Confirmation/"})
          var $field = $(event.currentTarget),
          $display = $field.prev("span.item-display");
          $display.html($field.find(":input:first").val());
          $display.show();
          $field.hide();
        })
    );

Open in new window


and the Action
[HttpPost]

       public ActionResult Confirmation(AgentConfirmationViewModel records) //Save updated records

       {

            CWA_AgentEntities CWA = new CWA_AgentEntities();
            foreach (STAGING_TABLE_Details record in records.getConfirmationData)
            {
                STAGING_TABLE Old_Rec = CWA.STAGING_TABLE.Find(record.ID);
                Old_Rec.AGENT_ID = record.AGENT_ID;

                Old_Rec.AGENT_Name = record.AGENT_Name;

                Old_Rec.DBA_Name = record.DBA_Name;              

                [More fields.]     

            }
            CWA.SaveChanges();
            return this.Confirmation();

Open in new window


I know I am not sending data back with my ajax call but I was under the impression because I was using helpers it would take care of that + it used to work before there were changes made to the table but now I can't see what might be causing the problem.

Any help is GREATLY appreciated.
Niall292Asked:
Who is Participating?
 
Niall292Author Commented:
I eventually figure it out
I added data to my ajax call
data: $(#formConfirmation").serialize()

to look like $.ajax({ type: "POST", url: "/Agent/Confirmation/", data: $("#formConfirmation").serialize() })

when you look at it, it makes perfect sense, but it worked anyway
0
 
Niall292Author Commented:
This answered the question asked and posted the data
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.