This is a migrated thread and some comments may be shown as answers.
EditorForTemplate in a Window not posting data
2 Answers 72 Views
This is a migrated thread and some comments may be shown as answers.
Bill
Top achievements
Rank 1
Bill asked on 31 Oct 2012, 07:07 AM
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 Answers, 1 is accepted

Sort by
0
Dave
Top achievements
Rank 1
answered on 14 Nov 2012, 03:26 PM
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.
0
Dave
Top achievements
Rank 1
answered on 14 Nov 2012, 06:57 PM
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.
Asked by
Bill
Top achievements
Rank 1
Answers by
Dave
Top achievements
Rank 1
Share this question
or