I am using a ColorPicker as part of a new user form. The selected colour is intended to be used later in a Scheduler.
I have tried setting the Value to Model.Colour directly and, using a scrip via a hidden textbox but cannot get it to work; the Model.Colour field always returns null.
My views and script are shown below .
I would appreciate any ideas about what I am doing wrong.
The View; some fields have been stripped out for clarity
The view is called from this grid
As stated, I have tried populating the model directly from the .Value field without success so I am now updating the HiddenFor<> text field using the following script:
After selection I can see that the text field has been updated with the colour as expected but when clicking submit the returned colour is always null.
Thanks in anticipation of your help
I have tried setting the Value to Model.Colour directly and, using a scrip via a hidden textbox but cannot get it to work; the Model.Colour field always returns null.
My views and script are shown below .
I would appreciate any ideas about what I am doing wrong.
The View; some fields have been stripped out for clarity
@model ServiceUserViewModel<BR>@{<BR> ViewBag.Title = "New User";<BR>}<BR><BR>@using (Html.BeginForm())<BR>{<BR> @Html.AntiForgeryToken()<BR> @Html.ValidationSummary(true)<BR> <fieldset><BR> <legend>Registration Form</legend><BR> <table><BR> <tr><BR> <td class="editor-label"><BR> @Html.LabelFor(m => m.UserName)<BR> </td><BR> <td class="editor-field"><BR> @Html.EditorFor(m => m.UserName)<BR> @Html.ValidationMessageFor(m => m.UserName)<BR> </td><BR> </tr><BR> <tr><BR> <td class="editor-label"><BR> @Html.LabelFor(m => m.Password)<BR> </td><BR> <td class="editor-field"><BR> @Html.PasswordFor(m => m.Password)<BR> @Html.ValidationMessageFor(m => m.Password)<BR> </td><BR> </tr><BR> <tr><BR> <td class="editor-label"><BR> @Html.LabelFor(m => m.ConfirmPassword)<BR> </td><BR> <td class="editor-field k-password"><BR> @Html.PasswordFor(m => m.ConfirmPassword)<BR> @Html.ValidationMessageFor(m => m.ConfirmPassword)<BR> </td><BR> </tr><BR> <tr><BR> <td class="editor-label"><BR> @Html.LabelFor(m => m.FirstName)<BR> </td><BR> <td class="editor-field"><BR> @Html.EditorFor(m => m.FirstName)<BR> @Html.ValidationMessageFor(m => m.FirstName)<BR> </td><BR> </tr><BR> <tr><BR> <td class="editor-label"><BR> @Html.LabelFor(m => m.LastName)<BR> </td><BR> <td class="editor-field"><BR> @Html.EditorFor(m => m.LastName)<BR> @Html.ValidationMessageFor(m => m.LastName)<BR> </td><BR> </tr><BR> <tr><BR> <td class="editor-label"><BR> @Html.LabelFor(m => m.Colour)<BR> </td><BR> <td class="editor-field"><BR> @(Html.Kendo().ColorPicker()<BR> .Name("colourPicker")<BR> .Palette(ColorPickerPalette.WebSafe)<BR> //.Value(Model.Colour)<BR> .Events(events => events<BR> .Change("pickerSelect")<BR> )<BR> )<BR><BR> @Html.HiddenFor(m => m.Colour)<BR> @Html.ValidationMessageFor(m => m.Colour)<BR> </td><BR> </tr><BR> </table><BR> </fieldset><BR>}<BR><BR>@section Scripts {<BR> @Scripts.Render("~/bundles/jqueryval")<BR>}@(Html.Kendo().Grid<ServiceUserViewModel>()<BR> .Name("ServiceUsersGrid")<BR> .AutoBind(true)<BR> .Columns(columns =><BR> {<BR> columns.Bound(p => p.ServiceUserId).Hidden();<BR> columns.Bound(p => p.FirstName).Title("First Name");<BR> columns.Bound(p => p.LastName).Title("Last Name");<BR> columns.Command(command => command.Edit().UpdateText("Save")).Hidden();<BR> columns.Command(command => command.Destroy()).Width(100);<BR> })<BR> .ToolBar(toolbar => <BR> {<BR> toolbar.Create().Text("Add User");<BR> })<BR> .Editable(editable => editable.Mode(GridEditMode.PopUp).TemplateName("NewPerson"))<BR> .Sortable(sortable => sortable<BR> .AllowUnsort(true)<BR> .SortMode(GridSortMode.MultipleColumn))<BR> .Scrollable()<BR> .Events(e=>e.Edit("RenameNewUserWindow").DataBound("onDataBound").Change("onDataBound"))<BR> .DataSource(dataSource => dataSource<BR> .Ajax()<BR> .ServerOperation(false)<BR> .Events(events => events.Error("error_handler"))<BR> .Model(model =><BR> {<BR> model.Id(p => p.Id);<BR> model.Field(f => f.FirstName);<BR> model.Field(f => f.LastName);<BR> model.Field(f => f.Password);<BR> model.Field(f => f.ConfirmPassword);<BR> model.Field(f => f.Colour);<BR> })<BR> .Read(read => read.Action("ServiceUser_Read", "Services"))<BR> .Create(create => create.Action("ServiceUser_Create", "Services"))<BR> .Update(update => update.Action("ServiceUser_Create", "Services"))<BR> .Destroy(destroy => destroy.Action("ServiceUser_Destroy", "Services"))<BR> )function pickerSelect(e) {<BR> $("#Colour").val(e.value);<BR>}Thanks in anticipation of your help