客户
public class ClientModelData
{
public int ClientID { get; set; }
public string ClientName { get; set; }
public string Phone { get; set; }
public string Address { get; set; }
public IList<int> LocationID { get; set; }
}
控制器
[HttpPost]
public ActionResult AddClient(ClientModelData client)
{
Client _client = new Client()
{
//ClientCode=client.ClientCode,
ClientName = client.ClientName,
Phone = client.Phone,
Ext = client.Ext,
Address = client.Address,
CreatedBy = 1,
CreatedDate = DateTime.Now,
ModifiedBy = 1,
ModifiedDate = DateTime.Now,
ModifiedIP = Request.ServerVariables["REMOTE_ADDR"]
};
db.Clients.Add(_client);
try
{
db.SaveChanges();
}
catch (DbEntityValidationException dbEx)
{
string error = string.Empty;
foreach (var validationErrors in dbEx.EntityValidationErrors)
foreach (var validationError in validationErrors.ValidationErrors)
error += string.Format("Property: {0} Error: {1}", validationError.PropertyName,
validationError.ErrorMessage);
return Json(new
{
status = false,
message = "Unable to update information for selected client, please contact administrator. For detail <a class='errordetail'>click here</a>",
exception = error
});
}
return Json(_client);
}
我有一个复选框列表:
<ul class="locations">
@foreach (var item in Model.Locations)
{
<li>
<label>
<input type="checkbox" id="chkLocations" name="chkLocations"
value="@item.LocationID" />
@item.LocationTitle</label>
</li>
}
</ul>
** Json 对象包含以下值:**
var allVals = [];
$('#chkLocations:checked').each(function () {
allVals.push($(this).val());
});
var dataPacket = {
ClientName: $("#txtClientName").val(),
Phone: $("#txtPhone").val(),
Ext: $("#txtExt").val(),
Address: $("#txtAddress").val(),
LocationID: allVals
};
现在问题出现了,当我给出复选框:选中的项目时,它不会填充 ModelData Entity Location属性
图片:
问题出现 POSTING 表单...JQuery AJAX
图片: