EditorForTemplate in a Window not posting data

3 posts, 0 answers
  1. Bill
    Bill avatar
    38 posts
    Member since:
    Jun 2010

    Posted 31 Oct 2012 Link to this post

    I have an EditorFor template that renders fine inside a Kendo Window but posts an empty (null). ViewModel back when the form is submited.

    This only happens when the EditorFor template is rendered inside the Window control. The ViewModel is not empty when the EditorFor is outside of the Window.

    Yes, I verified

    @using (Html.BeginForm()) is working correctly.


    ListofChoices is an IEnumerable of the Choice ViewModel.



    ___VIEW_______________________________________________
    @(Html.Kendo().Window()
         .Name("window")
         .Title("Profile:")       
         .Content(@<text>
          <div>Test</div>
          @Html.EditorFor(y => y.ListofChoices);
           </text>)
           )

    <button id="get1" type="submit" >CONTINUE</button>


    ____EDITOR TEMPLATE___________________________________
    @model ViewModels.Choice
      
     @Html.CheckBoxFor(x=>x.IsSelected)
     @Html.HiddenFor(x=>x.AccountResponsibilityId)
     @Html.LabelFor(x=>x.IsSelected, Model.AccountResponsibilityName)

     

     

  2. Dave
    Dave avatar
    35 posts
    Member since:
    Oct 2012

    Posted 14 Nov 2012 Link to this post

    I'm also having issues with posting data in a window.  Similar setup; I'm not loading content from another page or view, but putting markup into the Window's Content.

    My Html.BeginForm doesn't work at all (won't POST to the controller), whether I put it inside the window, or wrap the window with it.

    In addition, if I use jQuery to POST via AJAX, the form's contents are still not posted and my model is empty.

    Relevant code snippet:

    @(Html.Kendo().Window()
            .Name("editIssueModal")
            .Title(Model.Title)
            .Width(650)
            .Height(230)
            .Modal(true)
            .Draggable()
            .Events(e => e.Open("centerWindow").Close("closeWindow"))
          .Content(@<text>
                    @using (Html.BeginForm("EditIssue", "ExistingIssues"))
                    {
                            [ all my fields]
                    }
                    </text>))
    Any help getting this form to work and post values correctly inside a Kendo window would be appreciated.
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Dave
    Dave avatar
    35 posts
    Member since:
    Oct 2012

    Posted 14 Nov 2012 Link to this post

    I was able to solve my problem (in a less ideal way) with the following.

    I don't give the window any content at all upon load. I do it later through javascript.

    I moved my Window to my main view (rather than the Partial View where I had it). No content. Here is the window:

    @(Html.Kendo().Window()
            .Name("editIssueModal")
            .Width(650)
            .Height(230)
            .Modal(true)
            .Draggable()
            .Visible(false)
            .Events(e => e.Open("centerWindow")))
    Then I "refresh" the window when the user clicks a button:

    function beginEdit() {
        var window = $('#editIssueModal').data('kendoWindow');
        var issue = selectedGridData();
        var issueId = issue.Id;
        window.refresh({
            url: '@Url.Action("BeginEdit")',
            data: { id: issueId }
        });
          
        window.open();
    }
    This then renders the Partial View in the window and opens it. Now, my POST actions are working correctly and the posted data binds to my ViewModel.

    Hope this helps you in some way, Bill.
Back to Top