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


    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:
        .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
            .Window(w => w
                .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
            .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())
    ... all labels and fields...
    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?


  2. Answer
    Petur Subev
    Petur Subev avatar
    1882 posts

    Posted 17 Jun 2013 Link to this post

    Hello Neils,

    Similar question is covered here:

    Kind Regards,
    Petur Subev
    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