Missing 1 of 3 values in ajax call

I am having a bit of a problem in my ajax call, I am getting 2 of my 3 values passed and everything works if i hard code my 3rd value for the db updates but for the life of me i am not seeing why 1 value is not being passed from the view to the controller. I am sure i am just not seeing a mistake i am making.

From the below the only value not being passed correctly is inc which is a number. I know that I am missing that number due to the return json message showing a 0 for that value and if i hard code the value in my sql the update works for the other 2 values.


from view:
@{
    var webGrid = new WebGrid(Model);
}

@webGrid.GetHtml(
        htmlAttributes: new { @id = "WebGrid", @class = "Grid" },
        columns: webGrid.Columns(
        webGrid.Column("Inc", format: @<text>  <span class="display-mode">@item.Inc</span> <label id="Inc" class="edit-mode">@item.Inc</label> </text>, style: "col1Width"),
        webGrid.Column("Include", "Include", format: @<text>  <span class="display-mode"> <label id="lblInclude">@item.Include</label> </span> <input type="text" id="Include" value="@item.Include" class="edit-mode" /></text>, style: "col2Width"),
        webGrid.Column("Desc", "Description", format: @<text>  <span class="display-mode"> <label id="lblDesc">@item.Desc</label> </span> <input type="text" id="Desc" value="@item.Desc" class="edit-mode" /></text>, style: "col2Width"),
        webGrid.Column("Action", format: @<text>
            <button class="edit-inc display-mode">Edit</button>
            <button class="save-inc edit-mode">Save</button>
            <button class="cancel-inc edit-mode">Cancel</button>
        </text>, style: "col3Width", canSort: false)))


@section Scripts{
    <script type="text/javascript" >  
        $(function () {  
            $('.edit-mode').hide();  
            $('.edit-inc, .cancel-inc').on('click', function () {  
                var tr = $(this).parents('tr:first');  
                tr.find('.edit-mode, .display-mode').toggle();  
            });        
            $('.save-inc').on('click', function () {  
                var tr = $(this).parents('tr:first');  
                var Include = tr.find("#Include").val();  
                var Desc = tr.find("#Desc").val();  
                var Inc = tr.find("#Inc").html(); 
                tr.find("#lblInclude").text(Include);  
                tr.find("#lblDesc").text(Desc);
                tr.find('.edit-mode, .display-mode').toggle();  
                var UpDateModel =  
                {  
                    "Inc": Inc,  
                    "Desc": Desc,  
                    "Include": Include  
                };  
                $.ajax({  
                    url: '/Inc/ChangeInc/',  
                    data: JSON.stringify(IncUpDateModel),  
                    type: 'POST',  
                    contentType: 'application/json; charset=utf-8',  
                    success: function (data) {  
                        alert(data);  
                    }  
                });  
       
            });  
        })  
    </script>  

Open in new window


controller:
     
  public JsonResult ChangeInc(UpDateModel model)
        {
            using (SqlConnection sqlCon = new SqlConnection(connectionString))
            {
                sqlCon.Open();
                string query = "UPDATE incTable SET  Include = @Include, Desc = @Desc WHERE Inc = @Inc";
                SqlCommand sqlCmd = new SqlCommand(query, sqlCon);
                sqlCmd.Parameters.AddWithValue("@Inc", model.Inc);
                sqlCmd.Parameters.AddWithValue("@Include", model.Include);
                sqlCmd.Parameters.AddWithValue("@Desc", model.Desc);
                sqlCmd.ExecuteNonQuery();
            }

        
            string message = "Success" + model.Inc + ":" + model.Include + ":" + model.Desc;
            return Json(message, JsonRequestBehavior.AllowGet);
        }

Open in new window



Thank you for any help
Justin HullAsked:
Who is Participating?
 
leakim971Connect With a Mentor PluritechnicianCommented:
Line 34, you've :
                var UpDateModel =  
                {  
                    "Inc": Inc,  
BUT use : IncUpDateModel
with that line 42 :
data: JSON.stringify(IncUpDateModel),  

you should use :
data: JSON.stringify(UpDateModel),  
or :
data: UpDateModel,
0
 
Julian HansenCommented:
Can we see the rendered result of this page (view source => HTML)
Paste that here (in CODE tags) so we can see what the AJAX is acting on.
0
 
Justin HullAuthor Commented:
sorry about not using the tags, will do so . I cant copy and paste the full page, its pretty long any how so let me take the parts i hope you need to see:

from the web grid
        <tr>
            <td class="col1Width">  <span class="display-mode">251201005920</span> <label id="Inc" class="edit-mode">180201004890</label> </td>
            <td class="col2Width">  <span class="display-mode"> <label id="lblInclude"></label> </span> <input type="text" id="Include" value="" class="edit-mode" /></td>
            <td class="col2Width">  <span class="display-mode"> <label id="lblDesc"></label> </span> <input type="text" id="Desc" value="" class="edit-mode" /></td>
            <td></td>
            <td class="col3Width">
            <button class="edit-inc display-mode">Edit</button>
            <button class="save-inc edit-mode">Save</button>
            <button class="cancel-inc edit-mode">Cancel</button>
        </td>

Open in new window

0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
Justin HullAuthor Commented:
I think some of that was me changing models around trying to troubleshoot, causing the name mismatch.  I got the call to work,
Matching what was in view source got me on the correct track
Thank you for your help.
1
 
leakim971PluritechnicianCommented:
don't forget to close the question...
0
 
leakim971PluritechnicianCommented:
could you explain me why you accepted Julian Hansen as solution? I believe you did an error the first time...
0
 
Justin HullAuthor Commented:
Well I select that option as it was the closest to a solution. Honestly there is no solution in this thread and I ended up resolving the issue my self. So I don't know how to close this thread in a manner that is acceptable to you.
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.