KendoUI Grid Default with Data Annotation

I am using the Kendo UI Grid using ASP.NET MVC helpers and automatically generated columns.

I have an annotation [DefaultValue(60 * 60)]in my view model, but Kendo's helpers do not seem to respect this.

Is it possible to set a default value (possibly with data annotations) without having to manually describe columns?

+4
source share
2 answers

if you defined the columns in the grid manually, you need to set a default value similar to this, although you defined the default value in the annotation or not

 @(Html.Kendo()
      .Grid()
      .DataSource( d=> d.Ajax()
                        .Model(m=>{
                            m.Field(f=>f.YourField).DefaultValue(YourValue);
                 }))
)

@(Html.Kendo()
      .Grid()
      .Events( e => e.Edit("onEdit"))
)

<script type="text/javascript">
      function onEdit(e) {   
           //check if record is new
           if (e.model.isNew()) {
                // set the value of the model property like this                    
                e.model.set("PropertyName", Value);
                // for setting all fields, you can loop on 
                // the grid columns names and set the field
           }
    }
</script>

,

+5

, , , Kendo , .

public class ViewModel
{

    public string Name { get; set; }

    public ViewModel()
    {
        Name = "First name";
    }

}

- , , , . . http://docs.telerik.com/kendo-ui/aspnet-mvc/helpers/grid/faq#how-do-i-specify-default-property-values-when-a-new-item-is-created.

+2

Source: https://habr.com/ru/post/1569148/


All Articles