2013-10-28 32 views
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();"/> 

请帮助。

回答

0

只是使用viewbag。这取决于你步上并在视图

@if(!ViewBag.PostBack){ 
    @Html.Partial("_p2") 
} 
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 Class

有趣的一个会onBegin和onComplete如果你想显示进度指示器

相关问题