简体   繁体   English

在Kendo窗口中时,部分视图中的MVC4 Ajax表单返回整个页面

[英]MVC4 Ajax form in partial view returns whole page when inside kendo window

I've searched and searched and for the life of me cannot figure out what I'm doing wrong. 我一直在搜寻,对于我的一生,我无法弄清楚自己在做什么错。 I have a Kendo UI window like so: 我有一个Kendo UI窗口,如下所示:

<a id="@(item.POD_ID)"  class="k-button btn-reminder" title="Add Reminder" onclick="$('#windowR@(item.POD_ID)').data('kendoWindow').open();"><span class="icon-reminder icon-only btn-reminder"></span></a
    @(Html.Kendo().Window()
    .Name("windowR" + item.POD_ID)
    .Title("Set Reminder")
    .Content("loading...")
    .LoadContentFrom("_LoadReminder", "Purchasing", new { id = item.POD_ID })
    //.Iframe(true)
    .Draggable()
    //.Resizable()
    .Modal(true)
    .Visible(false)
    .Width(200)
    .Height(80)
    .Events(events => events
        .Close("onCloseReminder")
        .Open("onOpenReminder")
        .Deactivate("function() { this.refresh();}")
        .Activate("function(){ $('#empNumBox').focus(); }")
    )
)

And, if the window is an Iframe, all of this works just fine, however I cannot have it as an Iframe, because that means reloading all of the scripts and styles within it and more difficult to reference parent. 而且,如果窗口是Iframe,则所有这些工作都很好,但是我不能将其作为Iframe,因为这意味着需要重新加载其中的所有脚本和样式,并且更难引用父级。

So this window, loads content from the partial view like so: 因此,此窗口从局部视图加载内容,如下所示:

@using (Ajax.BeginForm("SetReminders", "Purchasing", new AjaxOptions { UpdateTargetId = "result" }))
{
<div id="result"></div>
<input type="number" id="empNumBox" name="empNum" style="width: 70px" class="k-textbox" required autofocus="autofocus" value="@(ViewBag.EMP_NUM)"/>
<input type="hidden" value="@ViewBag.POD_ID" name="podID" id="POD_ID_Form_Field"/>
<input type="submit" id="submitReminder_button" style="width:auto;" class="k-button submitReminder_button" value="Remind" />
}

That partial view also renders fine. 该局部视图也很好。 Here is the problem though, when you submit the ajax form, and the kendo window is not an iframe, it will render the whole page as whatever the controller returns (and I have tried several things, you can see in the commented out code below: 但是,这是问题所在,当您提交ajax表单,并且kendo窗口不是iframe时,它将以控制器返回的内容呈现整个页面(并且我已经尝试了几件事,您可以在下面的注释代码中看到) :

        [HttpPost]
    public ActionResult SetReminders(int empNum, int podID)
    {
        //some database stuff that works fine

        string response;
        if (existingReminder == 0)
        {
            //more db stuff that also works fine
            db.SaveChanges();
            response = "Success!";
        }
        else
        {
            response = "Reminder exists.";
            //return PartialView("_LoadReminder", new string[] { "Reminder already exists!" });
        }
        // $('#submitReminder_button').closest('.k-window-content').data('kendoWindow').close();
        //alert('Hello world!');
        //return Content("<script type='text/javascript/>function(){alert('Hello world!');}</script>");
        return PartialView("_SubmitSuccess");
        //return Json(response);
        //return Content(response, "text/html");
    }

If anyone is curious, all that the _SubmitSuccess contains is the word "Success!". 如果有人好奇,则_SubmitSuccess包含的所有单词都是“ Success!”。

Here's an example that I found with the ajax response being put in a div, which I followed: http://pratapreddypilaka.blogspot.com/2012/01/htmlbeginform-vs-ajaxbeginform-in-mvc3.html 这是我发现的一个示例,并将ajax响应放入div中,然后按照以下步骤进行操作: http : //pratapreddypilaka.blogspot.com/2012/01/htmlbeginform-vs-ajaxbeginform-in-mvc3.html

It seems the real issue here is the Kendo window, but I have yet to find something on their forums about this, doesn't seem that there's a lot of examples of using a kendo window to load a partial view that submits an form via ajax and returns a different partial view to be loaded within the same window and does not use an iframe. 似乎真正的问题是Kendo窗口,但是我还没有在他们的论坛上找到有关此的东西,似乎没有很多使用kendo窗口加载通过ajax提交表单的局部视图的示例。并返回要在同一窗口内加载的其他局部视图,并且不使用iframe。

Any suggestions welcome, even about other parts of the code, I'm always looking to improve. 欢迎提出任何建议,甚至关于代码的其他部分,我也一直在寻求改进。

尝试将SetReminders()的返回类型更改为PartialViewResult

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM