代码列子:
public ActionResult FindUserByUserId(SysMessageDTO model)
{
CustomResultMsg customResult = new CustomResultMsg() { ResultValue = 1 };
try
{
RecordLogExtension.WriteError(model.DateTimeFrom.ToString()+model.DateTimeTo.ToString());
var data = userDetailService.GetUserCollection(model);
if(data!=null)
{
customResult.Data = data;
customResult.ResultValue = 0;
}
}catch(Exception e)
{
customResult.Msg = "系统繁忙,请稍后重试";
RecordLogExtension.WriteError(string.Format("error message in FindUserByUserId: Error Message:{0}", e.Message));
}
var json= Newtonsoft.Json.JsonConvert.SerializeObject(customResult);
//var content=new ContentResult() {Content=new JavaScriptSerializer { MaxJsonLength = Int32.MaxValue }.Serialize(customResult),ContentType="application/text" };
return Content(json);--这里返回的是Json格式:
}
在页面上用:Data=$.ParseJson(data)
$('#search').click(function () {
var model = {
DateTimeFrom: document.getElementById('startTime').value,
DateTimeTo: document.getElementById('endTime').value
}
if (model.DateTimeFrom != null && model.DateTimeTo != null) {
$.ajax({
type: 'POST',
url: '/Message/FindUserByUserId',
data: {
model: model
},
success: function (data) {
var datas=$.parseJSON(data);
selectleft = datas.Data;
selectUpdate();
},
error: function (data) {
console.log(data);
}
});
}
});