I currently store the model, which is a list of a model which contains different data such as id, name etc, in a JSON object. I pass this model back to a controller action. The problem is the List contains the correct amount but all the data with the model are null. Below is my code:
Model:
#region Client Employees
public class EmployeesModel
{
public string Id { get; set; }
public string Division { get; set; }
public string Location { get; set; }
public string Level { get; set; }
public string Firm { get; set; }
public double? Bonus { get; set; }
public double? Salary { get; set; }
public double? Compensation { get; set; }
}
public class ViewEmployeesModel
{
public List<EmployeesModel> employees { get; set; }
}
#endregion
Controller:
public ActionResult Index()
{
var clients = DeepfieldClient.GetAllClientEmployees();
ViewEmployeesModel employees = new ViewEmployeesModel
{
employees = clients
};
return View(employees);
}
public JsonResult GetClients(List<EmployeesModel> model)
{
//Do something with the clients in the model
return Json(false);
}
Js:
GetClientData: function ()
{
$("#GetDataBtn").on("click", function () {
var searchCriteria = $(".dataSelectOptions").val();
$.ajax({
type: "POST",
url: "Home/GetClients",
data: { model: model },
success: function (response) {
GetData.FillTable(response);
}
});
});
},
model is stored in the view as:
var model = @Html.Raw(Json.Encode(Model.employees))
Any ideas as why i will be retrieving the correct amount but null values?
modellooks like when written into page, that could give a clue.