部分视图不在ajax帖子上呈现 [英] Partial view not rendering on ajax post

查看:78
本文介绍了部分视图不在ajax帖子上呈现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Main.cstml,它是一个普通视图,我在其中渲染2个部分视图。



Main.cshtml的代码



I have a Main.cstml which is a normal view inside which I am rendering 2 partial views.

Code for Main.cshtml



@ Html.Partial(Partial1)


@Html.Partial("Partial1")

< br $>






@ Html.Partial(Partial2)


@Html.Partial("Partial2")





Partial1.cshtml代码



@model PartialViewDemo2.Models.Product

@using(Ajax.BeginForm(Partial1,Home,

新的AjaxOptions()))

{

@ Html.TextAreaFor(m => m.Name)

< input type =submitid =SubmitButton/>

}



同样在Partial2.cshtml上有一些控件



控制器上的代码



Code for Partial1.cshtml

@model PartialViewDemo2.Models.Product
@using (Ajax.BeginForm("Partial1", "Home",
new AjaxOptions()))
{
@Html.TextAreaFor(m => m.Name)
<input type="submit" id="SubmitButton" />
}

Similarly there are some controls on Partial2.cshtml

Code on controller

[HttpPost]
        public ActionResult Partial1(Product product)
        {
            return View(product);
        }





当我点击Partial1.cshtml上的提交按钮时,我想要渲染两个视图,但仅限于Partial1被渲染,Partial2熄灭。

我用一个非常简单的演示代表了我的问题。请帮助。



When I click on submit button present on Partial1.cshtml, I want both the views to render, but only Partial1 gets rendered and Partial2 goes off.
I have represented my problem here using a very simple demo. Kindly help.

推荐答案

您的AJAX代码正在使用MVC生成的东西。您的页面上有两个表单。他们都使用AJAX更新自己。它们是离散的。你最好的选择可能是从一个表单成功返回,触发另一个表单,这是一个单独的AJAX调用,在一个单独的表单中获取一个单独的数据块。另一种方法是在jquery中编写自己的AJAX代码,然后你就可以完全控制并可以更新你喜欢的页面上的任何内容。
Your AJAX code is using the stuff generated by MVC. You have two forms on your page. They both update themselves using AJAX. They are discrete. Your best bet is probably to make the successful return from one form, fire the other one, it's a separate AJAX call to get a separate block of data inside a separate form. An alternative is to write your own AJAX code in jquery, then you have full control and can update anything on the page that you like.


这篇关于部分视图不在ajax帖子上呈现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆