我是使用ExtJS的新手,现在我正在尝试使用ext.ajax.request调用Controller方法并将模型作为参数传递。
但是一旦调用了Method,参数就返回NULL
EmployeeModel.cs:
public class Employee
{
[Key]
public int EmployeeId { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string OfficeLocation { get; set; }
public string PhoneNumber { get; set; }
}
CODE:
public void UpdateEmployee(Employee emp)
{
using (GLContext db = new GLContext ())
{
var employee = db.Employees.SingleOrDefault(e => e.Id == emp.Id);
db.Entry(employee).State = EntityState.Modified;
db.SaveChanges();
}
}
}
SCRIPT:
var emp = empGrid.getStore().getAt(context.rowIdx);
var newEmp = Ext.create('EmpModel', {
EmployeeId: emp.data.EmployeeId,
FirstName: context.newValues.FirstName,
LastName: context.newValues.FirstName,
OfficeLocation: context.newValues.FirstName,
PhoneNumber: context.newValues.FirstName
});
Ext.Ajax.request({
url: '/Home/UpdateEmployee',
method: 'POST',
params: {
emp: newEmp.data
},
});
我已将newEmp.data添加到监视列表,它具有值
newEmp.data: Object
EmployeeId:2
FirstName:"sergyguk"
LastName:"serthyuk"
OfficeLocation:"rthgyuk"
PhoneNumber:"drhtyguk"
但是当它调用Controller方法时,它会返回一个错误,因为(Employee emp)参数为null
我很感激任何帮助 感谢