首页 文章

使用ASP.NET MVC在Kendo UI Grid中自动递增列

提问于
浏览
1

是否可以创建一个Kendo Grid,每次添加新记录时,Id列增加1?例如,我有一个简单的模型类,有3个属性:Id,Title,Salary:

public class JobViewModel
{
    public int Id { get; set; }
    public string Title { get; set; }
    public double Salary { get; set; }
}

Grid的剃刀代码如下所示:

@(Html.Kendo().Grid<Kendo.Mvc.Examples.Models.JobViewModel>()    
    .Name("JobListing")    
    .Columns(columns => {        
        columns.Bound(x => x.Id);
        columns.Bound(x => x.Title);
        columns.Bound(x => x.Salary);
    .Editable(editable => editable.Mode(GridEditMode.InCell))
    .DataSource(dataSource => dataSource        
        .Ajax()         
        .Batch(true)
        .ServerOperation(false)
        .Model(model => model.Id(m => m.Id))
        .Create("Editing_Create", "Grid")
     )
)

而不是用户键入Id值,我想知道是否有一种方法来自动增加它 .
因此,当添加新记录时,"Editing_Create" Action方法会收到一个
JobViewModel对象,其中属性设置如下:

job.Id = 1 //下次这将是2,3 ...
job.Title = "whatever the user typed"
job.Salary = "whatever the user typed"

1 回答

相关问题