0

Why can't I post an object containing both a model and a integer(id) from mvc view to action using jQuery? I am trying to post an object containing a model and a (int)ID from my view to MVC action.The problem is, I can post id(int) but cannot pass Model, while the controller receives the ID correctly but Model is empty. I tried many things but it doesn't work and Model is always empty.But when I just pass model on its own then it works(not empty). Can someone suggest me some idea?

jQuery Code:

$.ajax({
    type: 'post',
    url: '@Url.Action("AddProfileAddress", "Account")',
    data: {
        model1: $('#frmAddProfileAddress').serialize(),
        id: 3
    }
});

Controller

<HttpPost()> _
Public Function AddProfileAddress(ByVal model1 As Address, id As Integer) As ActionResult
{
    ...
}

What am I doing wrong?

user1128681
  • 23
  • 1
  • 8

1 Answers1

-1

The solution is below:

             $.ajax({
                        type: 'POST',
                        url: '@Url.Action("AddProfileAddress", "Account")',
                        data: $('#frmAddProfileAddress').serialize()+"&addresstypeid="+addresstypeid,
                        beforeSend: function () {
                            //launchpreloader();
                            $("div#spinner").fadeIn("fast");
                        },
                        complete: function () {
                            //stopPreloader();
                            $("div#spinner").fadeOut("fast");
                        },
                        success: function (result) {
                            //alert(result);
                        }
                    });
Brad Larson
  • 170,088
  • 45
  • 397
  • 571
user1128681
  • 23
  • 1
  • 8