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
JustinAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
JustinAuthor 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
leakim971PluritechnicianCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CompTIA Security+

Learn the essential functions of CompTIA Security+, which establishes the core knowledge required of any cybersecurity role and leads professionals into intermediate-level cybersecurity jobs.

JustinAuthor 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
JustinAuthor 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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET MVC

From novice to tech pro — start learning today.