Create action not being called in ListView

2 posts, 1 answers
  1. Steve
    Steve avatar
    13 posts
    Member since:
    Aug 2008

    Posted 25 Sep 2013 Link to this post

    I am attempting to use the Create action in ListView for MVC4 according to the Getting Started example, but the Create action does not get called. The Read, Update, and Destroy actions do get called as expected. Here is relevant code, and any help would be appreciated:
    From the view:
    @model VentSettings
     
    <div class="k-toolbar k-grid-toolbar">
        <a class="k-button k-button-icontext k-add-button" href="#"><span class="k-icon k-add"></span>Add new record</a>
    </div>
     
    <script type="text/x-kendo-tmpl" id="ventTemplate">
        <div>
           <div class="edit-buttons" style="width:98%; background:lightgray; border:1px solid lightgray; padding:10px;">#:Time#
                <a style="float:right" class="k-button k-button-icontext k-edit-button" href="\\#"><span class="k-icon k-edit"></span>Edit</a>
                <a style="float:right" class="k-button k-button-icontext k-delete-button" href="\\#"><span class="k-icon k-delete"></span>Delete</a>
            </div>
     
            <div style="width: 98%; padding:10px; border:1px solid lightgray;">
                <span style="width:10%; display: inline-block">Rate:</span><span style="width:22%; display:inline-block">#:Rate#   per min</span>
                <span style="width:10%; display: inline-block">PIP:</span><span style="width:22%; display:inline-block">#:PIP#   cm H<sub>2</sub>O</span>
                <span style="width:10%; display: inline-block">PEEP:</span><span style="width:22%; display:inline-block">#:PEEP#   cm H<sub>2</sub>O</span>
                <span style="width:10%; display: inline-block">MAP:</span><span style="width:22%; display:inline-block">#:MAP#   cm H<sub>2</sub>O</span>
                <span style="width:10%; display: inline-block">Vent:</span><span style="width:50%; display:inline-block">#:VentDescription# </span>
            </div>
        </div>
    </script>
     
    @(Html.Kendo().ListView<VentSetting>(Model.VentSettingsList)
        .Name("listView")
        .TagName("div")
        .ClientTemplateId("ventTemplate")
        .Editable()
        .DataSource(datasource => datasource
            .Events(events => events.Sync("handleSync"))
            .Model(model => model.Id(m => m.VentSettingId))
            .Read(read => read.Action("ReadVentSettings", "RunDetail"))
            .Create(create => create.Action("CreateVentSetting", "RunDetail"))
            .Update(update => update.Action("UpdateVentSetting", "RunDetail"))
            .Destroy(destroy => destroy.Action("DeleteVentSetting", "RunDetail"))
        )
    )
     
    <script>
     
    function handleSync() {
        this.read();
    }
     
    </script>
    The relevant part of the EditorTemplate:
    <div style="padding:10px">
        @Html.ValidationSummary(true)
         
        <span style="width:12%; display:inline-block">Resp Rate: </span>
         <span style="width:36%; display:inline-block"> @Html.Kendo().DropDownListFor(x => x.VentTypeId).DataValueField("VentTypeId").DataTextField("Description").BindTo((System.Collections.IEnumerable)ViewData["VentTypes"])</span>
         
     
        <div class="edit-buttons">
            <a class="k-button k-button-icontext k-update-button" href="\\#"><span class="k-icon k-update"></span>Save</a>
            <a class="k-button k-button-icontext k-cancel-button" href="\\#"><span class="k-icon k-cancel"></span>Cancel</a>
        </div>
     
    </div>
    From the controller, the Create action (does not get called) and the Update action (gets called). I've tried the Create action with and without the second parameter:
    [HttpPost]
    public ActionResult CreateVentSetting([DataSourceRequest] DataSourceRequest request, Models.VentSetting modelVentSetting)
    {
        if (modelVentSetting != null && ModelState.IsValid)
        { // Create code... }
     
        return Json(ModelState.ToDataSourceResult());
    }
     
    [HttpPost]
    public ActionResult UpdateVentSetting([DataSourceRequest] DataSourceRequest request, Models.VentSetting modelVentSetting)
    {
        // Update code...
     
        return Json(ModelState.ToDataSourceResult());
    }
    Thanks in advance!
    Steve
  2. Answer
    Steve
    Steve avatar
    13 posts
    Member since:
    Aug 2008

    Posted 26 Sep 2013 Link to this post

    I have obtained a solution to the problem, with the answer discussed in this post.
  3. Kendo UI is VS 2017 Ready
Back to Top