C# 可编辑的.net核心内联数据表
如何在.net核心项目中使用可编辑的数据表。 无法理解如何在控制器中通过ajax调用传输数据。 例如,我有一个方法C# 可编辑的.net核心内联数据表,c#,asp.net-core,datatables,C#,Asp.net Core,Datatables,如何在.net核心项目中使用可编辑的数据表。 无法理解如何在控制器中通过ajax调用传输数据。 例如,我有一个方法 [HttpPost] public JsonResult SaveWorkPageData() { var m = //want to get data from request in this veriable return Json(); } [HttpPost] public JsonResult Search(string orderBy, List<O
[HttpPost]
public JsonResult SaveWorkPageData()
{
var m = //want to get data from request in this veriable
return Json();
}
[HttpPost]
public JsonResult Search(string orderBy, List<Order> order, Search search,
int start, int length, string searchTerm, bool isAsc, bool hideVoidedAndDeclined, bool recent = false)
{
var take = length;
var skip = start;
var m = _clientsService.Search(searchTerm, orderBy, hideVoidedAndDeclined, isAsc, take, skip, recent);
return Json(m);
}
如何更改使用数据的
SaveWorkPageData
方法?在客户端,您要声明编辑器,然后激活它:
var editor = new $.fn.dataTable.Editor({
ajax: '@Url.Action("ProductOutputList")',
table: '#productoutputs',
fields: [
{
"label": "Name:",
"name": "productoutputs.Name"
}], //more fields
formOptions: {
inline: {
onBlur: 'submit'
}
}
});
// Activate an inline edit on click of a table cell
$('#productoutputs').on('click', 'tbody td.editable', function (e) {
editor.inline(this);
});
在服务器端,您希望处理请求。因此,数据将被传输到控制器,您可以使用编辑器插件处理它(文档在这里):
公共操作结果ProductOutputList()
{
var request=System.Web.HttpContext.Current.request;
var settings=Properties.settings.Default;
使用(var db=new数据库(settings.DbType,settings.DbConnection))
{
var响应=新编辑器(db,“productoutputs”,“ProductOutputId”)
.Model()
.Field(新字段(“productoutputs.ProductId”)
.选项(“产品”、“产品ID”、“名称”)
)
.LeftJoin(“products”、“products.ProductId”、“=”、“productoutputs.ProductId”)
.Field(新字段(“productoutputs.DesignId”)
.选项(“设计”、“设计ID”、“名称”)
)
.程序(请求)
.Data();
返回Json(response,JsonRequestBehavior.AllowGet);
}
}
您还希望为数据库连接创建设置:
在客户端,您要声明编辑器,然后激活它:
var editor = new $.fn.dataTable.Editor({
ajax: '@Url.Action("ProductOutputList")',
table: '#productoutputs',
fields: [
{
"label": "Name:",
"name": "productoutputs.Name"
}], //more fields
formOptions: {
inline: {
onBlur: 'submit'
}
}
});
// Activate an inline edit on click of a table cell
$('#productoutputs').on('click', 'tbody td.editable', function (e) {
editor.inline(this);
});
在服务器端,您希望处理请求。因此,数据将被传输到控制器,您可以使用编辑器插件处理它(文档在这里):
公共操作结果ProductOutputList()
{
var request=System.Web.HttpContext.Current.request;
var settings=Properties.settings.Default;
使用(var db=new数据库(settings.DbType,settings.DbConnection))
{
var响应=新编辑器(db,“productoutputs”,“ProductOutputId”)
.Model()
.Field(新字段(“productoutputs.ProductId”)
.选项(“产品”、“产品ID”、“名称”)
)
.LeftJoin(“products”、“products.ProductId”、“=”、“productoutputs.ProductId”)
.Field(新字段(“productoutputs.DesignId”)
.选项(“设计”、“设计ID”、“名称”)
)
.程序(请求)
.Data();
返回Json(response,JsonRequestBehavior.AllowGet);
}
}
您还希望为数据库连接创建设置:
是否要获取ajax请求的响应数据<代码>ajax:“客户端/SaveWorkPageData”是。我想在答案中添加响应数据示例,让我知道!是否要获取ajax请求的响应数据<代码>ajax:“客户端/SaveWorkPageData”是。我想在答案中添加响应数据示例,让我知道!我试着这么做。但是不能,因为我认为它只用于asp.NETMVC。而我使用.net Core,我试图做到这一点。但是不能,因为我认为它只用于asp.NETMVC。我用的是.NETCore
public ActionResult ProductOutputList()
{
var request = System.Web.HttpContext.Current.Request;
var settings = Properties.Settings.Default;
using (var db = new Database(settings.DbType, settings.DbConnection))
{
var response = new Editor(db, "productoutputs", "ProductOutputId")
.Model<ProductOutputDatatablesModel>()
.Field(new Field("productoutputs.ProductId")
.Options("products", "ProductId", "Name")
)
.LeftJoin("products", "products.ProductId", "=", "productoutputs.ProductId")
.Field(new Field("productoutputs.DesignId")
.Options("designs", "DesignId", "Name")
)
.Process(request)
.Data();
return Json(response, JsonRequestBehavior.AllowGet);
}
}