简体   繁体   English

新的部分视图不呈现

[英]New Partial View does not render

I tried to load a second partial view after I submitted info from my first partial view but on submit, my partial view just refreshes and it says on the same partial view instead of the new one. 从第一个局部视图提交信息后,我尝试加载第二个局部视图,但是在提交时,我的局部视图只是刷新,并且在同一局部视图上显示,而不是在新局部视图上显示。 I'm not sure why since I'm positive I set up my controller actions and razor code to load the partial view correctly. 我不确定为什么,因为我肯定我会设置控制器动作和剃刀代码来正确加载部分视图。 I think it might be with how I'm doing the js but I'm not sure. 我认为这可能与我的js工作方式有关,但我不确定。

Here's the ajax call when I click on submit on the first partial view. 这是我在第一个局部视图上单击“提交”时的ajax调用。 On submit, I would like to load the second view: 关于提交,我想加载第二个视图:

var SubmitInfo = function () {

    var form = $('form#FirstForm');
    var result = form.valid();
    var dataToSerialize = form.serialize();

    if (result) {
        $.ajax({
            url: Url.getFullUrl('Home/FormOneInfo'),
            type: 'Post',
            data: dataToSerialize,
            cache:false,
            success: function (data) {

                LoadFormTwo(data);
            }
        });
    }
    return result;
}

var LoadFormTwo  = function (data) {

    $.ajax({
        type: "GET",
        url:  Url.getFullUrl("Home/FormTwoInfo"),
        success: function (data) {  }
    });
}

Just to be clear, when I call the second ajax method, it goes to my controller action. 需要明确的是,当我调用第二个ajax方法时,将转到我的控制器操作中。 In my action, I set a bool,DisplayFormTwo, to true and then in my main view with the specific div, I have something like this: 在我的操作中,我将boolDisplayFormTwo设置为true,然后在具有特定div的主视图中,我得到了以下内容:

<div class="centerDivContent">
               if (Model.DisplayFormOne == true){
                    @Html.Partial("FormOne", new ViewModels.FormOneViewModel())
               else if(Model.DisplayFormTwo == true) {
                    @Html.Partial("FormTwo", new ViewModels.FormTwoViewModel())
               }
         </div>

This part does get hit in the debugger but a new view is not rendered. 在调试器中确实会命中此部分,但是不会呈现新视图。

我可能读错了,但调用LoadFormTwo时不应该将数据放入容器中

success: function (data) { $(someElement).append(data) }

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

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