This is a migrated thread and some comments may be shown as answers.

model.Field(field => field.NoReference).DefaultValue("Test") not Working (string type)

1 Answer 84 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Louis
Top achievements
Rank 1
Iron
Iron
Iron
Louis asked on 24 Aug 2019, 02:35 PM

Hello,

@(Html.Kendo().Grid<Myproject.Areas.Maintenance.ViewModels.EquipementsInterventions.EquipementInterventionModel>()
            .Name("EquipementIntervention")
            .Columns(columns =>
            {
                columns.Bound(p => p.NoReference).Width(60);
                columns.Bound(p => p.DateIntervention).Format("{0:yyyy-MM-dd}").Width(60).HtmlAttributes(new { style = "text-align:center" });
            })
            .ToolBar(toolBar =>
            {
                toolBar.Create();
                toolBar.Save();
            })
            .Editable(editable => editable.Mode(GridEditMode.InCell))
            .HtmlAttributes(new { style = "font-size:11px;height: 300px;" })
            .Scrollable()
            .Selectable(s => s.Enabled(false))
            .Pageable(pageable => pageable
            .Refresh(true)
            .ButtonCount(5))
            .DataSource(dataSource => dataSource
                .Ajax()
                .Batch(true)
                .ServerOperation(false)
                .PageSize(100)
                .Model(model =>
                {
                    model.Id(field => field.NoEquipementIntervention);
                    model.Field(field => field.NoReference).DefaultValue("Test");
                    model.Field(field => field.DateIntervention).DefaultValue(System.DateTime.Now);
                })
                .Read(read => read.Action("Read", "Equipements", new { id = Model.EquipementId }))
                .Create(create => create.Action("Create", "Equipements", new { id = Model.EquipementId }))
                .Update(update => update.Action("Update", "Equipements"))
                .Destroy(destroy => destroy.Action("Destroy", "Equipements"))
            )
)

I try to set a default value when I add a new item in my grid.  Even with a hard coded value like "Test".  I have the same situation with a DateTime? field until I remove the ?.  Any idea about the NoReference (string) field?

The model :

[Key]
public Guid NoId { get; set; }
 
[Required]
 
public string NoReference { get; set; }
 
[UIHint("Date")]
[Required]
public DateTime DateIntervention { get; set; }

 

The Grid :

 

 

THANK A LOT TO EVERYONE.

 

 

 

1 Answer, 1 is accepted

Sort by
0
Viktor Tachev
Telerik team
answered on 27 Aug 2019, 10:21 AM

Hi Louis,

 

There is a known issue in the latest release that is prevents the default value from being applied. The issue has been fixed and will not be present in the upcoming release that is scheduled for mid-September. 

Until then, if you would like to test the fix I suggest downloading the latest internal build of the components. You can get it from the download section on telerik.com after logging in.

 

Give the internal build a try and let me know how it works for you.

 

Regards,
Viktor Tachev
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Grid
Asked by
Louis
Top achievements
Rank 1
Iron
Iron
Iron
Answers by
Viktor Tachev
Telerik team
Share this question
or