ListView with editor template for foreign key type

2 posts, 1 answers
  1. Steton
    Steton avatar
    4 posts
    Member since:
    Jul 2006

    Posted 17 Sep 2013 Link to this post

    Hello, I am having an issue where I have not been able to associate a selected item from a DropDownList to the submitted values of an editor template from my ListView.

    Partial view that renders the ListView:
        .DataSource(dataSource => dataSource
            .Model(model =>
                    model.Field(f => f.CorrectiveActionPlanID).DefaultValue(this.Model.CorrectiveActionPlanID);
                    model.Field(f => f.CorrectiveActionItemType);
            .Create(create => create.Action("Item_Create", "CorrectiveActionItem", new { this.Model.CorrectiveActionPlanID }))
            .Read(read => read.Action("Items_Read", "CorrectiveActionItem", new { this.Model.CorrectiveActionPlanID }))
            .Update(update => update.Action("Item_Update", "CorrectiveActionItem"))
            .Destroy(destroy => destroy.Action("Item_Destroy", "CorrectiveActionItem"))
    Editor Template for CorrectiveActionItemModel:
    @using Steton.Web.MVC.Model
    @model CorrectiveActionItemModel
    <div class="corrective-action-item-display">
        <div class="edit-buttons">
            <a class="k-button k-button-icontext k-update-button" href="\\#"><span class="k-icon k-update"></span></a>
            <a class="k-button k-button-icontext k-cancel-button" href="\\#"><span class="k-icon k-cancel"></span></a>
        @Html.HiddenFor(m => m.CorrectiveActionItemID)
        @Html.HiddenFor(m => m.CorrectiveActionPlanID)
        <div class="action-section">
            @Html.LabelFor(m => m.DirectiveText)
            @Html.TextAreaFor(m => m.DirectiveText)
        <div class="action-section">
            @Html.LabelFor(m => m.ActionTakenText)
            @Html.TextAreaFor(m  => m.ActionTakenText)
        <div class="action-section">
            <div style="clear:both">
                <div class="action-sub-edit-section">
                        @Html.LabelFor(m => m.DueDate)
                        @Html.LabelFor(m => m.IsCompleted)
                        @Html.CheckBoxFor(m => m.IsCompleted)
                <div class="action-sub-edit-section">
                        @Html.LabelFor(m => m.CorrectiveActionItemType)
                        @Html.EditorFor(m => m.CorrectiveActionItemType)
    Editor template for CorrectiveActionItemType:
    @using System.Collections
        .DataSource(read => read.Read("Types","CorrectiveActionItem", new { correctiveActionPlanID = "#=CorrectiveActionPlanID#" })))
    Now, when the CorrectiveActionItemModel is submitted I do not get any item in the POST for CorrectiveActionItemType. I suspect that there is some binding or setup that needs to occur in order to get the DropDownList's value to be associated to the model of CorrectiveActionItemModel.

    I have tried following the pattern at Editor template documentation, but I could not get the .BindTo((IEnumerable)ViewData["CorrectiveActionType"])) even though I added it the controller that renders the ListView.

    Any thoughts or ideas would be appreciated, thanks.

  2. Answer
    Daniel avatar
    2110 posts

    Posted 19 Sep 2013 Link to this post


    You should use the DropDownListFor helper instead of the DropDownList helper. 

    @model MyFieldType
    @(Html.Kendo().DropDownListFor(model=> model)
    Since the EditorFor helper is used, the prefix in the editor will be the property name, and so the property that will actually be edited will be "CorrectiveActionItemType.CorrectiveActionItemType" when setting the name.

    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. UI for ASP.NET AJAX banner
Back to Top