Link to home
Start Free TrialLog in
Avatar of Niall Gallagher
Niall GallagherFlag for Ireland

asked on

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.
ASKER CERTIFIED SOLUTION
Avatar of Niall Gallagher
Niall Gallagher
Flag of Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Niall Gallagher

ASKER

This answered the question asked and posted the data