日期:2014-05-17 浏览次数:20568 次
function TestExport() {
if (datagrid_data.total == 0) {
$.messager.alert('提示', "查询结果区域没有数据可导出", 'info');
} else {
var columns = $('#dg').datagrid("options").columns;
//alert(JSON.stringify(columns));
//alert(JSON.stringify(datagrid_data));
$.post("/Export/ExportData", { data: JSON.stringify(datagrid_data), columns: JSON.stringify(columns) }, function (result) {
if (result.success) {
alert(1);
} else {
$.messager.alert('提示', result.msg, 'error');
}
}, "json");
}
}
public ActionResult ExportData([ModelBinder(typeof(JsonBinder))]object data, [ModelBinder(typeof(JsonBinder))]List<Object> columns)
{
//啥都没写
return Json(new { success = true });
}
public class JsonBinder : IModelBinder
{
public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
{
//从请求中获取提交的参数数据
var json = controllerContext.HttpContext.Request.Form[bindingContext.ModelName] as string;
//提交参数是对象
if (json.StartsWith("{") && json.EndsWith("}"))
{
Dictionary<string, object> JsonObj = new Dictionary<string, object>();