MVC4阿贾克斯形式的局部视图返回时,里面的剑道窗口整页剑道、视图、局部、形式

2023-09-10 20:42:07 作者:╰一丝微笑掩饰千般不舍

我找啊找,为我的生活不能找出我做错了。我有一个剑道UI窗口,如下所示:

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:

<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(); }")
    )
)

和,如果窗口是一个IFRAME,所有这一切都工作得很好,但我不能把它作为一个IFRAME,因为这意味着重装所有的脚本和风格在其中,更难以引用父。

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.

所以这个窗口,加载内容来自像这样的局部视图:

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" />
}

这部分观点也呈现良好。这里的问题是,虽然,当你提交的Ajax表单,并且剑道窗口不是一个iframe,它会呈现为任何控制器返回(我已经试过几件事情的整个页面,您可以在注释掉$ C见低于$ C:

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:

        [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");
    }

如果有人想,所有的_SubmitSuccess包含的单词成功了!。

If anyone is curious, all that the _SubmitSuccess contains is the word "Success!".

下面是我发现的Ajax响应被放在一个分区,我跟着一个例子: 的http://prata$p$pddypilaka.blogspot.com/2012/01/htmlbeginform-vs-ajaxbeginform-in-mvc3.html

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表单,并返回一个不同的局部视图要在同一窗口中加载,并且不使用iframe。

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.

任何建议表示欢迎,甚至对的code其他地方,我一直在寻找改善。

Any suggestions welcome, even about other parts of the code, I'm always looking to improve.

推荐答案

试着改变的 SetReminders()返回类型 PartialViewResult