AntiForgeryToken gets lost in editing custom editor

3 posts, 1 answers
  1. Heiko
    Heiko avatar
    153 posts
    Member since:
    Oct 2012

    Posted 13 Jun 2013 Link to this post

    Hi!

    I'm new to MVC4 and thus built some little demo including a Kendo UI Grid and a partial view which serves as a custom editor. Everything works perfect except that the AntiForgeryToken gets lost on the way.

    This is my definition of the grid:
    @(Html.Kendo().Grid(Model)
        .Name("grdProducts")
        .Columns(columns =>
            {
                columns.Bound(p => p.Name);
                columns.Bound(p => p.ProductType);
                columns.Bound(p => p.SellStartDate);
                columns.Bound(p => p.SellEndDate);
                columns.Command(command => command.Edit()).Width(160);
            })
        .ToolBar(toolbar => toolbar.Create())
        .Editable(editable => editable
            .Mode(GridEditMode.PopUp)
            .DisplayDeleteConfirmation(true)
            .TemplateName("ProductEditor")
            .Window(w => w
                .Width(700)
                .Title("Edit Product")))
        .Pageable(pa => pa.Numeric(false).PageSizes(new [] {5,10,20}))
        .Scrollable(scr => scr.Height(430).Virtual(false))
        .Selectable(selectable => selectable.Mode(GridSelectionMode.Single))
        .DataSource(dataSource => dataSource
            .Ajax()
            .AutoSync(false)
            .Batch(false)
            .PageSize(20)
            .ServerOperation(false)
            .Model(model =>
                {
                    model.Id(p => p.Id);
                    model.Field(p => p.Id).Editable(false);
                    model.Field(p => p.CategoryName).Editable(false);
                    model.Field(p => p.ProductType).DefaultValue((int)ProductTypeEnum.Cameras);
                })
            .Create(create => create.Action("EditingCreate", "Product"))
            .Read(read => read.Action("EditingRead", "Product"))
            .Update(update => update.Action("EditingUpdate", "Product"))
        )
    )
    And this is the start of my partial view named "ProductEditor.cshtml" saved in subdir "EditorTemplates":
    @model _ProductStore.Infrastructure.Models.Products.Product

    @{
        ViewBag.Title = "Edit";
    }

    @using (Html.BeginForm())
    {
        @Html.AntiForgeryToken()
        @Html.ValidationSummary(true)
     
        <fieldset>
    ... all labels and fields...
        </fieldset>
    }
    The popup opens as it should and everything works fine except that the hidden input for AntiForgeryToken looks like this:
    <input name="__RequestVerificationToken" type="hidden" data-bind="value:__RequestVerificationToken" value=""/>
    In other words: the value is empty. Placing the AntiForgeryToken helper somewhere else in my views it is working perfectly.

    What am I doing wrong?

    Regards
    Neils






  2. Answer
    Petur Subev
    Admin
    Petur Subev avatar
    1882 posts

    Posted 17 Jun 2013 Link to this post

    Hello Neils,

    Similar question is covered here:

    http://www.kendoui.com/forums/ui/grid/kendo-grid-antiforgerytoken.aspx


    Kind Regards,
    Petur Subev
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. Heiko
    Heiko avatar
    153 posts
    Member since:
    Oct 2012

    Posted 24 Jun 2013 Link to this post

    Thanks, that did the trick!
Back to Top