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

Color picker in bound grid never sets the model property

1 Answer 211 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Karl
Top achievements
Rank 1
Karl asked on 24 Aug 2015, 03:14 PM

I am trying to use the grid with a colorpicker to set a colorcode property on my model and even so the column is bound, I can never see the updated code when the model is sent to the controller.  I am using the standard in line editing function of the grid. (which manages to update teh model for simple properties.

CSHTML

@(Html.Kendo().Grid<Tetral.Services.Entities.AllocationPortfolioEntity>()
        .Name("grid")
        .Columns(columns =>
        {
            columns.Bound(p => p.ColourCode).Title("Colour").Width("84px").ClientTemplate("<span style='display: inline-block; width: 100%; height: 100%; background-color: #= ColourCode #'>&nbsp;</span>");
            columns.Command(m =>
            {
                m.Edit();
                m.Destroy();
            }).Width(260);    

        })
        .HtmlAttributes(new { style = "height:850px;width:100%" })
        .BindTo(@Model)
        .Scrollable(scr => scr.Enabled(true))
        .DataSource(dataSource => dataSource
            .Ajax()
            .Model(m => m.Id(p => p.Id))
            .Create(update => update.Action("AllocationPortfolioInsert", "DataManagement"))
            .Update(update => update.Action("AllocationPortfolioUpdate", "DataManagement"))
            .Destroy(update => update.Action("AllocationPortfolioDelete", "DataManagement"))
        )   

 

TEMPLATE

@model string
@(Html.Kendo().ColorPickerFor(m => m)
    //.Palette(ColorPickerPalette.Basic)
    .Name("ColourPicker")
    .Events(e => e.Change("colourPickerChange"))
)

 

MODEL

    private string colourCode;
        [UIHint("ColourPicker")]
        public string ColourCode
        {
            get { return colourCode; }
            set { this.colourCode = newValue;}
        }

1 Answer, 1 is accepted

Sort by
0
Karl
Top achievements
Rank 1
answered on 25 Aug 2015, 08:01 AM
I found what the issue was.  Unless the name property of the colour picker control is called exactly the same as the model property, the binding will not work
Tags
Grid
Asked by
Karl
Top achievements
Rank 1
Answers by
Karl
Top achievements
Rank 1
Share this question
or