Starting with v15.1, GridLookup can be automatically bound to a model field that returns an array of values (see DevexpressEditorsBinder - Support binding multiple values selected in MVC editor extensions to a Model's collection-type property)
This example illustrates how to use GridLookup in a multiple selection mode (SelectionMode is Multiple) as a GridView editor. The main idea is to use the MVCxGridViewColumn.SetEditItemTemplateContent method to place GridLookup in EditForm. The same approach will work for a custom EditForm (GridViewSettings.SetEditFormTemplateContent) as well.
Note that prior to version 16.1.6, the GridLookupExtension.Bind method doesn't automatically select required keys. It's necessary to assign a delegate method to the PreRender property to manually select the values using the GridViewSelection.SelectRowByKey method. Starting with version 16.1.6, it is sufficient to pass values to bind/select to the GridLookupExtension.Bind method.
[C#]//Prior to version 16.1.6 onlysettings.PreRender=(s,e)=>{MVCxGridLookuplookup=sasMVCxGridLookup;for(inti= 0;i<Model.TagIDs.Length;i++)lookup.GridView.Selection.SelectRowByKey(Model.TagIDs[i]);};
[VB.NET]'Prior to version 16.1.6 only settings.PreRender = Sub(s, e)Dim lookup As MVCxGridLookup = TryCast(s, MVCxGridLookup)For i AsInteger = 0 To Model.TagIDs.Length - 1 lookup.GridView.Selection.SelectRowByKey(Model.TagIDs(i))Next iEndSub
In order to use client-side unobtrusive JavaScript validation with GridLookup, it's necessary to pass a correct model instance to a partial view. This instance should be of the same type as an item of the collection bound to GridView.
Controller:
[C#]publicActionResultGridLookupPartial(int?KeyParameter){varmodel=GetModelInstanceByKey(KeyParameter);returnPartialView(model);}
[VB.NET]PublicFunction GridLookupPartial(ByVal KeyParameter?AsInteger) As ActionResultDim model = GetModelInstanceByKey(KeyParameter)Return PartialView(model)EndFunction
PartialView:
[C#]@Html.DevExpress().GridLookup(settings=>{settings.Name=PropertyName;}).BindList(...).Bind(Model.PropertyName).GetHtml()
[VB.NET]@Html.DevExpress().GridLookup(Sub(settings) settings.Name = PropertyNameEndSub).BindList(...).Bind(Model.PropertyName).GetHtml()
See also:
GridView - How to use GridLookup with single selection mode in EditForm
Web Forms:
How to use two-way data-bound ASPxGridLookup in edit form of ASPxGridView to edit data
How to use ASPxGridLookup in multiple selection mode as the ASPxGridView editor