I wish to make a grid within my visual studio program to display DateTime.now as a default but it's not working.
我希望在我的visual studio程序中创建一个网格,将DateTime.now显示为默认值,但它不起作用。
The column within the Kendo grid:
Kendo网格中的列:
columns.Bound(c => c.CurrentDate).EditorTemplateName("Date").Format("{0:dd/MM/yy}");
The declaration within my model:
我的模型中的声明:
public DateTime CurrentDate { get; set; }
When I load the web page the value of the text box within the column is set to the current date but value is not displayed.
加载网页时,列中文本框的值设置为当前日期,但不显示值。
My Kendo UI Grid Code:
我的Kendo UI网格代码:
@(Html.Kendo().Grid()
.Name("EIDGrid") .Columns( 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("Date");//.EditorTemplateName("Date") 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 .Ajax() .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(true) .Sort(s => s.Add("Name")) ) )
My Model code:
我的型号代码:
using System; using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Web;
使用系统;使用System.Collections.Generic;使用System.Globalization;使用System.Linq;使用System.Web;
namespace Kendo_UI_Bootstrap_Integration.Models {
namespace Kendo_UI_Bootstrap_Integration.Models {
public class EID { public string Breed { get; set; } public string Gender { get; set; } public string AnimalId { get; set; } public int EIDNum { get; set; } public int BatchNum { get; set; } public DateTime EIDDate { get; set; } public int ClusterIndex { get; set; } public System.Guid SireGuid { get; set; } } }
My Controller Code:
我的控制器代码:
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc;
使用系统;使用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(); } } }
namespace Kendo_UI_Bootstrap_Integration.Controllers {public class EidController:Controller {// GET:Eid public ActionResult EidView(){return View(); }}}
1 个解决方案
#1
0
Try something like this:
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));
}
You have to define a way your grid is populated by data. In this case I use .Read function to query controller method EIDRead for rows. Of course you can pass your data directly to the grid, but this method is much easier for maintainance.
您必须定义网格由数据填充的方式。在这种情况下,我使用.Read函数来查询行的控制器方法EIDRead。当然,您可以将数据直接传递给网格,但这种方法更易于维护。
#1
0
Try something like this:
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));
}
You have to define a way your grid is populated by data. In this case I use .Read function to query controller method EIDRead for rows. Of course you can pass your data directly to the grid, but this method is much easier for maintainance.
您必须定义网格由数据填充的方式。在这种情况下,我使用.Read函数来查询行的控制器方法EIDRead。当然,您可以将数据直接传递给网格,但这种方法更易于维护。