Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6171201
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:10:21+00:00 2026-05-23T23:10:21+00:00

i am trying to post my model to the server through an ajax call.

  • 0

i am trying to post my model to the server through an ajax call. Unfortunately the Model is not updated?

 <script src="../../Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>

<form id="ajaxForm" action="">
    <div>
        name:<%= Html.TextBoxFor(model => model.number) %>
    </div>
    <%--hidden vars--%>
    <input type="hidden" id="Hidden1" />
    <%= Html.Hidden("myModel", Model.Serialize())%>
</form>
<button id="submitbutton">
    save
</button>

<script type="text/javascript">

    $(document).ready(function () {
        $("#submitbutton").click(function () {
            var FormData = $("#ajaxForm").serialize();
            $.ajax({
                type: 'POST',
                url: "/Home/SaveAjax",
                data: { inputdata: $("#myModel").val() },
                datatype: 'JSON'
            });
        })
    });

</script>




    [HttpPost]
    public JsonResult SaveAjax(string inputdata)
    {
        MyModel myModel = (inputdata.DeSerialize() ?? TempData["myModel"] ?? new MyModel()) as MyModel;

        //TryUpdateModel does not update my model??
        TryUpdateModel(myModel);

        TempData["myModel"] = myModel;

        return Json(new { resultaat = "finished" });
    }


 [Serializable]
public class MyModel
{
    //[Required]
    public string name { get; set; }
    public bool flag { get; set; }
    public int number { get; set; }
    public string address { get; set; }
    public string abn { get; set; }
    public string postalcode { get; set; }
}


public static class Extensions
{
    public static string Serialize(this object myobject)
    {
        var sw = new StringWriter();
        var formatter = new LosFormatter();
        formatter.Serialize(sw, myobject);
        return sw.ToString();
    }

    public static object DeSerialize(this string mystring)
    {
        if (string.IsNullOrEmpty(mystring))
            return null;
        var formatter = new LosFormatter();
        MyModel mym = (MyModel)formatter.Deserialize(mystring);
        return mym;
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T23:10:23+00:00Added an answer on May 23, 2026 at 11:10 pm

    In your AJAX request you are sending only the value of the hidden field:

    data: { inputdata: $("#myModel").val() }
    

    so you cannot expect to get any other values on your server than this hidden field. If you want to POST the entire form contents use the formData variable that you declared in your code but left unused:

    $('#submitbutton').click(function () {
        var formData = $('#ajaxForm').serialize();
        $.ajax({
            type: 'POST',
            url: '/Home/SaveAjax',
            data: formData,
            dataType: 'json'
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some jQuery that looks like this: $.ajax({ type: POST, url: /Customer/CancelSubscription/<%= Model.Customer.Id
I'm trying to POST a http request using ajax, but getting a response from
I am trying to mock the server response for a POST request using Sinon.js.
I am just trying to learn how to use JQuery AJAX with ASP.NET MVC
I am using Asp.net MVC3 and trying to do a simple Ajax post to
I am trying to POST a HTML (contained in a file) to a URL
I'm trying to POST to the HTTP gateway of an SMS provider (Sybase 365)
I am trying to post an array full of checkboxes and to open it
I am trying to post something on a facebook users feed and then afterwards
I'm trying to post some code on a blog using the pre tag. Something

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.