I am working on project and i got requirement to send javaScript array "selectedZonesList", holding data back to controller along with form data. I been given one suggestion to use Ajax.BeginForm ... but i am struggling to put all parts togather many thanks...
in partial view
@using (Html.BeginForm("CreateNewFeeScheme", "Qualification", FormMethod.Post, new { id = "NewFeeSchemeForm" }))
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
//rest of code to take user input for all variables ..
<input type="submit" value="Create" class="btn btn-default" />
}
JavaScript function
<script type="text/javascript">
var selectedZonesList = new Array();
function AddFeeZoneToScheme(e)
{
var entityGrid = $("#FeeZoneGrid_02").data("kendoGrid");
var selectedZone = entityGrid.dataItem(entityGrid.select());
selectedZone = selectedZone.FeeZoneID;
selectedZonesList.push(selectedZone);
}
</script>
Controller
[HttpPost]
public ActionResult CreateNewFeeScheme(FeeScheme newSchemeData, ??????)
{
You can do it with simple JQuery AJAX POST. You can pass Stirngly Typed model along with array of strings in a single AJAX JQuery post.
And then the controller action -
When you hit the button, then you will get the values on server side like this -
Sample model which I have used is PersonViewModel -
You can pass your javascript object to server by two ways.
Assign your object to a element in the form so when you post the form you ll get the object in controller.
Use Ajax post, attach your object with form data and send it to server.
Similar question on SO
Posting JS Array object to mvc via ajax post
i have issue of send both data together but thanks to ramiramilu guide, i have figure out the solution ....
Get SerializeObject plugin
script