Sunil Chaudhry Sunil Chaudhry - 1 year ago 78
jQuery Question

Unable to get all ajax parameters in MVC Controller

When creating ajax call to controller getting 2nd parameter only.


return $http({
method: "post",
url: "/myform/AddEmployee",
data: '{ "EmpDetail":' + JSON.stringify(employee) + ', "File_ID":' + File_ID + '}',
//data: JSON.stringify(employee,File_ID),
dataType: "json"


public string AddEmployee(EmpDetail Emp, int? File_ID)


public partial class EmpDetail
public int Id { get; set; }
public string name { get; set; }
public System.DateTime DOB { get; set; }
public string Gender { get; set; }
public string Email { get; set; }
public string Mobile { get; set; }
public string Address { get; set; }
public System.DateTime JoiningDate { get; set; }
public int DepartmentID { get; set; }
public int DesignationID { get; set; }
public Nullable<int> FileId { get; set; }
public Nullable<int> CountryId { get; set; }
public Nullable<int> StateId { get; set; }

I have also tried

data: JSON.stringify(employee,File_ID)

I know this is wrong, but here I am getting first parameter only.

Answer Source

Try this,

 var empData= JSON.stringify({ EmpDetail: employee, File_ID: File_ID });

And ajax,

return $http({
          method: "post",
          url: "/myform/AddEmployee",
          data: empData,
          dataType: "json"

Hope helps.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download