0

我有一个视图“主页”,我在其中渲染了 2 个部分视图 _P1 和 _p2。以下是我在主页视图中的代码:

<div>
        <div>
            @Html.Partial("_P1")
        </div>

        <div>
            @Html.Partial("_p2")
        </div>
</div>

我在_P1 上有一个文本框和一个提交按钮,在_P2 上有一个标签,当我单击提交时,我希望发布数据,但将用户重定向到包含_P1 和_P2 的同一视图。但是 _P2 在提交后没有被渲染。

_P1 上的代码:

@using (Ajax.BeginForm("_P1", "Home", new AjaxOptions(), new { Id = "_P1form" }))
{
    @Html.LabelFor(m=>m.Name)
    @Html.TextBoxFor(m=>m.Name)
}
<input type="button" value="Save Form Data" class="save-button" onclick="submitform();"/>

请帮忙。

4

2 回答 2

0

以您正在执行的方式渲染第一个部分视图,但单击按钮时可以渲染第二个部分视图。更新您的开始以使用以下代码。

在 AjaxOptions 中,您可以执行以下操作

@using (
   Ajax.BeginForm("**Action Name from your controller**"
                   , "**Controller Name**"
                   , new  AjaxOptions
                    { 
                      HttpMethod ="Get", *// this can be get or post*
                      InsertionMode = InsertionMode.Replace, *// this will replace the content of the div. you can use the others like InsertAfter", "InsertBefore", or "Replace"*
                      UpdateTargetId="**Name of the div where you want to write the content**"
                    }
                 )
{

<div id="**div to be replaced**">
</div>

}

查看描述 ajax 选项方法可用的其他选项的 URL。AjaxOptions 类

如果您希望显示进度指示器,有趣的是 onBegin 和 onComplete

于 2013-10-29T05:14:54.620 回答
0

只需使用viewbag。根据您所在的步骤和视图在控制器上设置它

@if(!ViewBag.PostBack){
    @Html.Partial("_p2")
}
于 2013-10-28T14:28:19.230 回答