---
title: "Using jQuery AJAX to POST multiple variables to an ASP .NET MVC Controller"  
description: "Using jQuery AJAX to POST multiple variables to an ASP .NET MVC Controller"  
author: "Anonymous User"  
published: 2013-06-11  
updated: 2013-06-12  
canonical: https://www.mindstick.com/forum/1037/using-jquery-ajax-to-post-multiple-variables-to-an-asp-dot-net-mvc-controller  
category: "vb.net"  
tags: ["vb.net"]  
reading_time: 3 minutes  

---

# Using jQuery AJAX to POST multiple variables to an ASP .NET MVC Controller

Hi [Developers](https://www.mindstick.com/articles/12875/blunders-you-must-avoid-while-hiring-java-developers-to-get-the-best-fulfilling-your-needs), \
I have a controller to which I want to POST 2 items via AJAX: a [complex object](https://www.mindstick.com/forum/158088/unable-to-bind-a-view-with-the-complex-object-in-knockout-js) (my entire **[viewmodel](https://www.mindstick.com/forum/157215/what-is-viewmodel-in-mvc)**), and an integer (the id of a particular row). This particular project is in VB .Net, but [if someone](https://answers.mindstick.com/qa/99016/is-there-any-device-that-can-detect-if-someone-opens-your-backpack) can answer this in C#, that would be fine (I know both [languages](https://yourviews.mindstick.com/story/1463/some-oldest-languages-in-the-world-still-spoken) fairly well). Either language would work.\
I can POST the viewmodel to the controller without any problem. Once I try to include the integer, the controller can no longer route the request. I know that it is probably an issue of how I am formatting the data that I POST, but I haven't been able to figure out exactly what I need to do.\
My [controller action](https://www.mindstick.com/forum/34400/how-to-retrieve-form-values-in-controller-action) looks like:\
**<HttpPost>****Public [Function](https://www.mindstick.com/articles/13001/multi-statement-table-valued-user-defined-function-in-sql-server) UpdateFromDate(viewModel As RetirementBenefitEstimateViewModel, estimateId) As [ActionResult](https://www.mindstick.com/forum/33961/what-is-the-difference-between-actionresult-and-viewresult)** If viewModel IsNot Nothing AndAlso viewModel.Estimate IsNot Nothing AndAlso viewModel.Estimate.RetirementBenefitsEstimates IsNot Nothing Then**\**

```
      For Each item In viewModel.Estimate.RetirementBenefitsEstimates.Where(Function(est) est.EstimateId = estimateId)        ' this is where I update the affected row        item.UpdateFromDate(viewModel.DateOfBirth, viewModel.EmploymentStartDate, viewModel.PersonId)      Next item    End If    ' Get the previous ViewModel from session    PerformSessionAction(Of RetirementBenefitEstimateViewModel)(SessionConstants.RetirementEstimate, currentEstimate, SessionAction.GetVar)    ' update it's .Estimate property    currentEstimate.Estimate = viewModel.Estimate    ' save the updated ViewModel to session    PerformSessionAction(Of RetirementBenefitEstimateViewModel)(SessionConstants.RetirementEstimate, currentEstimate, SessionAction.SetVar)    ' finished!    Return New HttpStatusCodeResult(HttpStatusCode.OK)End Function
```

**The [jquery AJAX](https://www.mindstick.com/forum/157890/how-does-the-jquery-ajax-method-work-what-are-some-common-options-and-parameters-used-in-it) call in my view looks like:****\**

```
$.ajax({        type: "POST",        url: '@Url.Action("UpdateFromDate")',        data: { viewModel : model, estimateId : 3 }        contentType: "application/json; charset=utf-8",        dataType: "json",        async: false,        cache: false,        success: function (msg) {          //alert(JSON.stringify(msg));          return true;        },        error: function (XMLHttpRequest, textStatus, errorThrown) {          //alert(errorThrown);          return false;        }      });
```

**\**How can I POST my **viewmodel** and the integer?\
Thanks in advance.

## Replies

### Reply by AVADHESH PATEL

Hi Lois,\
You can try this\

```
var params = {    viewModel: model,    estimateId: 3};$.ajax({    url: '@Url.Action("UpdateFromDate")',    type: "POST",    dataType: 'json',    data: JSON.stringify(params),    async: false,    cache: false,    traditional: true,    contentType: 'application/json',    success: function  (msg) {      //alert(JSON.stringify(msg));      return true;    },    error: function (XMLHttpRequest, textStatus, errorThrown) {      //alert(errorThrown);      return false;    }  });  
```

**\**I hope it helpful for you. \


---

Original Source: https://www.mindstick.com/forum/1037/using-jquery-ajax-to-post-multiple-variables-to-an-asp-dot-net-mvc-controller

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
