Tuesday 18 November 2014

Send model data from view to controller using ajax call

 $("#btnSubmit").click(function () {
            var tommy = {
                FromDate: $("#FromDate").val(),
                ToDate: $("#ToDate").val()
            };

            $.ajax({
                url: "@Url.Action("SearchVehicle", "Default")",
               type: "POST",
               contentType: "application/json",
               data: JSON.stringify({ vehicleSearchParameter: tommy }),
               success: function (response) {
                   response ? alert("It worked!") : alert("It didn't work.");
               }
           });
        })

vehicleSearchParameter is a class  file model
tommy  is javascript object

public ActionResult SearchVehicle(VehicleSearchParameter vehicleSearchParameter, string Command)
        {
}