This is a migrated thread and some comments may be shown as answers.
Bound Column Client Template Problem
2 Answers 58 Views
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Top achievements
Rank 1
Fred asked on 28 Dec 2011, 09:05 PM
Hi.  I am new with mvc.  I am a windows form experienced programmer doing the jump to a mvc project.

I am using the telerik extensions for mvc 3 and razor.

I have been able to do a lot in a short time, but now i am stuck when it comes times to replace a fkID in a bound column by its DisplayText from a dropdownList.

I also want to see the dropdown in the edit

i was able to put a dropdown list on my view which containes all the Villes but it was on top of the view, not in the columns

in my model, my CITY_ID is defined as such

        <DisplayName("Ville")> _
        <UIHint("Cities"), Required()>
        Public Property CITY_ID As Nullable(Of Integer)
                Return _cityId
            End Get
            Set(value As Nullable(Of Integer))
                _cityId = value
            End Set
        End Property

In my Controller, 

i feed this viewData before return the view

 ViewData("Cities") = _db.GEO_CITY.ToList

In my View

    Dim Cities = ViewData("Cities") i create a variable to hold my cities

and then i declare my grid

    Html.Telerik.Grid(Model).Name("Grid") _
                           .ColumnContextMenu() _
                                     End Sub) _
                                                  commandes.Insert.ButtonType(type).ImageHtmlAttributes(New With {.style = "margin-left:0"})
                                          End Sub) _
                        databinding.Ajax() _
                            .Select("_AjaxIndex", "Fournisseurs") _
                            .Insert("_InsertAjaxEditing", "Fournisseurs") _
                            .Update("_AjaxEdit", "Fournisseurs") _
                            .Delete("_DeleteAjaxEditing", "Fournisseurs")
                End Sub) _
                    column.Bound("CITY_ID").Width(100).ClientTemplate("<#= Cities.Name#>")
                                   End Sub).Width(180).Title("Commands")
            End Sub) _
        .Editable(Function(ee) ee.Mode(mode)) _
        .Pageable _
        .Scrollable _
        .Sortable() _

It all works except for the dropdownlist which is not displayed nor is it used.

Anyone can help ?

thanks a happy holidays


2 Answers, 1 is accepted

Sort by
Top achievements
Rank 1
answered on 29 Dec 2011, 03:32 AM
We i have figured out half of my problem.

I created a viewModel that only exposes the properties i need (to bypass the circular reference problem) and used automapper 
to flatten the model and retrieve the description of the foreign key.

Works well if all i need is to show the data.... but if i want to edit it, i still got work to do

Top achievements
Rank 1
answered on 29 Dec 2011, 04:19 AM
this is a example from  the book pro mvc:

@model Role 
@model Role
<select id="Role" name="Role">
    @foreach (Role value in Enum.GetValues(typeof(Role))) {
        <option value="@value" @(Model == value ? "selected=\"selected\"" : "")>@value
Asked by
Top achievements
Rank 1
Answers by
Top achievements
Rank 1
Top achievements
Rank 1
Share this question