I developed a Grid which displays a pop-up for updates. Popup Edit screen is a Custom template with a dropdown list that calls the controller to populate the dropdown. In this case, i am populating the prefixes. The is populated fine, but when I click on a row on the grid to edit an item, I need to pre-select the value in the drop-down. let's say if a particular row has a value of "Mr." as a prefix, I need it to be pre-selected in the popup .
If the use of a @Html.EditorFor(model => model.Prefix), it perfectly populates the editor fine. This doesn't work for Dropdown.
The editor template is called MemberEdit and the code in it is as below:
<
p
></
p
><
p
>@model <
g
class
=
"gr_ gr_98 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace"
id
=
"98"
data-gr-id
=
"98"
>Api</
g
>.<
g
class
=
"gr_ gr_162 gr-alert gr_gramm gr_inline_cards gr_run_anim Punctuation multiReplace"
id
=
"162"
data-gr-id
=
"162"
>Common..</
g
>Models.WebUser<
br
><
br
> <
div
class
=
"row"
style
=
"margin-left:5px;"
><
br
> <
div
class
=
"col-lg-2"
><
br
> @Html.LabelFor(model => model.Prefix)<
br
> @*@Html.EditorFor(model => model.Prefix)*@<
br
> @(Html.Kendo().DropDownList()<
br
> .Name("ddlPrefix")<
br
> .DataTextField("Prefix")<
br
> .DataValueField("PrefixKey")<
br
> .DataSource(source =><
br
> {<
br
> source.Read(read =><
br
> {<
br
> read.Action("ListCustomerPrefix", "Home"); //.Data("additionalPrefixData");<
br
> })<
br
> .ServerFiltering(true);<
br
> })<
br
> // .Text(Model.Prefix)<
br
> .Value(Model.PrefixKey)<
br
> .AutoBind(false)<
br
> .HtmlAttributes(new { style = "width: 100%" })<
br
> )<
br
> @Html.ValidationMessageFor(model => model.Prefix)<
br
> </
div
><
br
> </
div
></
p
>
The Grid code is as shown below:
1.
@(Html.Kendo().Grid<.Api.Common..Models.WebUser>()<
br
> .Name("membersGrid")<
br
> .Columns(columns =><
br
> {<
br
> columns.Command(command => { command.Edit(); command.Destroy().Text("Del"); }).Width("15%");<
br
> columns.Bound(p => p.CST_KEY).Visible(false);<
br
> columns.Bound(p => p.FullName).Width("20%").Filterable(ftb => ftb.Cell(cell => cell.Operator("contains").SuggestionOperator(FilterType.Contains)));<
br
> columns.Bound(p => p.Role).Width("25%").Filterable(ftb => ftb.Cell(cell => cell.Operator("contains").SuggestionOperator(FilterType.Contains)));<
br
> columns.Bound(p => p.Title).Width("20%").Filterable(ftb => ftb.Cell(cell => cell.Operator("contains").SuggestionOperator(FilterType.Contains)));<
br
> columns.Bound(p => p.EmailAddress).Width("20%").Filterable(ftb => ftb.Cell(cell => cell.Operator("contains").SuggestionOperator(FilterType.Contains)));<
br
> columns.Bound(p => p.Prefix).Visible(false);<
br
> columns.Bound(p => p.Suffix).Visible(false);<
br
> columns.Bound(p => p.RoleKey).Visible(false);<
br
> columns.Bound(p => p.OrganizationMemberKey).Visible(false);<
br
><
br
> }).Filterable(filterable => filterable<
br
> .Extra(false)<
br
> .Operators(ops => ops<
br
> .ForString(str => str.Clear()<
br
> .Contains("Contains")<
br
> .StartsWith("Starts With")<
br
> .IsEqualTo("Is Equal To")<
br
> .IsNotEqualTo("Is Not Equal To")<
br
> )))<
br
> .Editable(editable => editable.Mode(GridEditMode.PopUp).TemplateName("MemberEdit").Window(w => w.Title("Edit Employee").Width(1100)))<
br
> .Pageable(pager => pager.AlwaysVisible(false).PageSizes(new List<
object
> { 5, 10, 15, 20 }))<
br
> .Sortable()<
br
> .Filterable(ftb => ftb.Mode(GridFilterMode.Row))<
br
> .HtmlAttributes(new { style = "width:100%;" })<
br
> .DataSource(dataSource => dataSource<
br
> .Ajax()<
br
> .PageSize(10)<
br
> .Events(events => events.Error("error_handler"))<
br
> .Model(model => model.Id(p => p.CST_KEY))<
br
> .Read(read => read.Action("ListMembers", "Home"))<
br
> .Update(update => update.Action("EditingPopup_Update", "Home"))<
br
> .Model(model =><
br
> {<
br
> model.Field(m => m.Title);<
br
> model.Field(m => m.Prefix);<
br
> model.Field(m => m.PrefixKey);<
br
> model.Field(m => m.Suffix);<
br
> model.Field(m => m.FirstName);<
br
> model.Field(m => m.MiddleName);<
br
> model.Field(m => m.LastName);<
br
> model.Field(m => m.OrganizationKey);<
br
> model.Field(m => m.FullName);<
br
> model.Field(m => m.CustomerId);<
br
> model.Field(m => m.OrganizationMemberKey);<
br
> model.Field(m => m.EmailAddress);<
br
> model.Field(m => m.CST_KEY);<
br
> model.Field(m => m.Role);<
br
> model.Field(m => m.RoleKey);<
br
> model.Field(m => m.RoleList).DefaultValue(new List<
Aamva.Api.Common.WebSite.Models.WebUserRole
>());<
br
> }<
br
> )<
br
> )<
br
> )
The Model is as below:
public
class
WebUser<br> {<br>
public
string
CST_KEY {
get
;
set
; }<br>
public
string
EmailAddress {
get
;
set
; }<br>
public
string
Prefix {
get
;
set
; }<br>
public
string
PrefixKey {
get
;
set
; }<br>
public
string
Suffix {
get
;
set
; }<br>
public
string
Title {
get
;
set
; }<br>
public
string
FirstName {
get
;
set
; }<br>
public
string
MiddleName {
get
;
set
; }<br>
public
string
LastName {
get
;
set
; }<br>
public
string
OrganizationKey {
get
;
set
; }<br>
public
string
OrganizationMemberKey {
get
;
set
; }<br>
public
string
OrganizationName {
get
;
set
; }<br>
public
string
Role {
get
;
set
; }<br>
public
string
RoleKey {
get
;
set
; }<br>
public
List<WebUserRole> RoleList {
get
;
set
; }<br>
}
The Model for Prefix is as below:
public
class
WebUserPrefix<br> {<br>
public
string
PrefixKey {
get
;
set
; }<br>
public
string
Prefix {
get
;
set
; }<br> }