Adding a new Listview item using a template calls the Create action multiple times!

2 posts, 0 answers
  1. Martin Kelly
    Martin Kelly avatar
    17 posts
    Member since:
    Jan 2010

    Posted 23 Jul 2012 Link to this post

    I have an MVC4 application and am trying to use the Listview using the MVC wrappers. I am using an edit and a view template. 
     If there are 4 items in my list and I add a new one the Create action is called 5 times, thus 5 records get added.

    I am using the latest Q2 trial version. However I previously had downloaded the beta trial version which included an MVC example project which showed the exact same behavour. Is this a bug?   
    (Note the same issue occurs for other actions as well)
    <div class="k-toolbar k-grid-toolbar">
        <a id="addRoleButton" class="k-button k-button-icontext k-add-button" href="#"><span class="k-icon k-add"></span>Add new Role</a>
            .DataSource(dataSource => dataSource           
                .Model(model =>
                        model.Field(f => f.ProjectId).DefaultValue(Model.ProjectId);
                        model.Field(f => f.Title);
                        model.Field(f => f.Description);;
                .Events(e => e               
                .Create(create => create.Action("createRole", "Project"))           
                .Read(read => read.Action("getRoles", "Project", new { projectId = Model.ProjectId }))
                .Update(update => update.Action("updateRole", "Project"))   
            .Events(e => e

    View Template
    //View template
    <script type="text/x-kendo-template" id="rolesList">
        <div class="roleView" >
            <div> ${Title} </div>
            <div> ${Description} </div>
            <div class="edit-buttons">
                <a class="k-button k-button-icontext k-edit-button" href="\\#"><span class="k-icon k-edit"></span>Edit</a>
                <a class="k-button k-button-icontext k-delete-button" href="\\#"><span class="k-icon k-delete"></span>Delete</a>

    Edit template
    @model iProjX.Models.RoleModel
    <div class="roleView" id "newRoleForm2" >
        @Html.HiddenFor(model => model.ProjectId)
        @Html.HiddenFor(model => model.RoleId)
        <div class="editor-label">
            @Html.LabelFor(model => model.Title)
        <div class="editor-field">
            @Html.TextBoxFor(model => model.Title, new { style = "width:99%", maxlength = 100 })
            <span data-for="Title" class="k-invalid-msg"></span>
        <div class="editor-label">
            @Html.LabelFor(model => model.Description)
        <div class="editor-field">
            @Html.TextAreaFor(model => model.Description, new { style = "width:100%; height:100px"})
            <span data-for="Description" class="k-invalid-msg"></span>
        <div class="edit-buttons">
            <a class="k-button k-button-icontext k-update-button" onclick="updateClick()" href="\\#"><spanclass="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>
  2. Michael
    Michael avatar
    8 posts
    Member since:
    Apr 2012

    Posted 20 Aug 2012 Link to this post

    Can you provide the code for your controller?  The action method should be caught there for example, ...
    public ActionResult ContactResearch_Read([DataSourceRequestDataSourceRequest request)
                return Json(GetContactResearch().ToDataSourceResult(request));         

    The _Create would be just another line item here and should not call the read method. Otherwise, are you
    returning the entire list back or just the item that you edited. I believe it only expects the item that was
Back to Top