首页 文章

将kendo ui网格中的列默认值设置为DateTime.Now

提问于
浏览
1

我希望在我的visual studio程序中创建一个网格,将DateTime.now显示为默认值,但它不起作用 .

Kendo网格中的列:

columns.Bound(c => c.CurrentDate).EditorTemplateName("Date").Format("{0:dd/MM/yy}");

我的模型中的声明:

public DateTime CurrentDate { get; set; }

加载网页时,列中文本框的值设置为当前日期,但不显示值 .

我的Kendo UI网格代码:

@(Html.Kendo() . Grid() . Name(“EIDGrid”)

. 列(
columns =>
{

columns.Bound(c => c.Breed);
columns.Bound(c => c.Gender);
columns.Bound(c => c.AnimalId);
columns.Bound(c => c.EIDDate).EditorTemplateName(“Date”) . ClientTemplate(DateTime.Now.ToString(“dd / MM / yy”)); // . ClientTemplate(DateTime.Now.ToString()) .Format( “{0:DD / MM / YY}”) . EditorTemplateName( “日期”); // EditorTemplateName( “日期”)
columns.Bound(c => c.EIDNum);
columns.Bound(c => c.BatchNum);
}

.Scrollable(s => s.Height(“350px”))
.Editable(editable => editable.Mode(GridEditMode.InCell).DisplayDeleteConfirmation(false))
.Pageable()
.DataSource(datasource => datasource

阿贾克斯()

.Model(model =>
{
model.Id(p => p.SireGuid);
//model.Field(p => p.SireGuid).DefaultValue(Guid.Empty);
//model.Id(p => p.EIDDate);
//model.Field(p => p.EIDDate).Editable(true);

})

.PageSize(100)
.Batch(真)
.Sort(s => s.Add(“Name”))
))

我的型号代码:

使用系统;使用System.Collections.Generic;使用System.Globalization;使用System.Linq;使用System.Web; namespace Kendo_UI_Bootstrap_Integration.Models {public class EID
{

公共字符串品种{get;组; }
public string Gender {get;组; }
public string AnimalId {get;组; }
public int EIDNum {get;组; }
public int BatchNum {get;组; }

public DateTime EIDDate {get;组; }

public int ClusterIndex
{
得到;组;
}
public System.Guid SireGuid {get;组; }
}}

我的控制器代码:

使用系统;使用System.Collections.Generic;使用System.Linq;使用System.Web;使用System.Web.Mvc; namespace Kendo_UI_Bootstrap_Integration.Controllers {public class EidController:Controller {// GET:Eid public ActionResult EidView(){return View(); }}}

1 回答

  • 0

    尝试这样的事情:
    Model:

    public class Eid
    {
        public string Breed { get; set; }    
        public DateTime EIDDate { get; set; } = DateTime.Now;
        public string SireGuid { get; set; }
    }
    

    MVC wrapper:

    @(Html.Kendo().Grid<KendoUIApp3.Models.Eid>()
        .Name("EIDGrid")
        .Columns(columns =>
        {
            columns.Bound(c => c.Breed);            
            columns.Bound(c => c.EIDDate).Format("{0:dd/MM/yy}");            
        })
        .Scrollable(s => s.Height("350px"))
        .Editable(editable => editable.Mode(GridEditMode.InCell).DisplayDeleteConfirmation(false))
        .Pageable()
        .Groupable()
        .Sortable()
        .DataSource(dataSource => dataSource
            .Ajax()
            .Model(model =>
            {
                model.Id(p => p.SireGuid);
            })
            .Read(read => read.Action("EIDRead", "Home"))
            .PageSize(100)
            .Batch(true)
            .Sort(s => s.Add("Breed"))
        ))
    

    Controller:

    public ActionResult EIDRead([DataSourceRequest] DataSourceRequest request)
        {
            var collection = new List<Eid>()
            {
               new Eid
               {
                   Breed = "test",
                   SireGuid = Guid.NewGuid().ToString()
               }
            };
    
            return Json(collection.ToDataSourceResult(request));           
        }
    

    您必须定义网格由数据填充的方式 . 在这种情况下,我使用.Read函数来查询行的控制器方法EIDRead . 当然,您可以将数据直接传递给网格,但这种方法更易于维护 .

相关问题