如何在其视图中仅刷新部分视图? [英] How can I refresh just a Partial View in its View?

查看:121
本文介绍了如何在其视图中仅刷新部分视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在做错人吗?这是主意...

What Am I doing wrong guys? This is the idea...

索引视图

<div class="col-lg-12 col-md-12 col-xs-12">
    @Html.Partial("PartialView", Model)
</div>

控制器

public ActionResult PartialView()
{
    return PartialView("PartialView");
}

[HttpPost, ValidateInput(false)]
public ActionResult POSTPartialView(string param1)
{
    return PartialView("PartialView");
}   

PartialView有一个窗体. 第一次输入Index时,PartialView起作用,但是第二次,在POST调用后(来自PartialView内部的表单),我只能从Index中渲染PartialView.

PartialView has a Form. The first time I enter in Index, PartialView works, but the second time, after a POST call (coming from the form inside of PartialView), I only got to render the PartialView out of the Index.

要解决此问题,我在下一个:

So to fix it, I´m doing the next:

[HttpPost, ValidateInput(false)]
public ActionResult POSTPartialView(string param1)
{
    return View("Index");
}   

那行得通.我再次渲染所有索引(在POST之后进行更改).但是我刷新了所有页面,所以丢失了一些CSS元素(例如,折叠式的手风琴).

That works. I render all Index again (with my changes, after POST). But I refresh all page so I lost a few CSS Elements (accordion discollapsed for example).

我应该使用Ajax仅刷新包含PartialView内容的div吗?

Should I use Ajax for refreshing only the div which contents PartialView?

感谢伙伴.

@using (Html.BeginForm("PartialView", "Controller", FormMethod.Post, new { @class = "form-inline", role = "form" }))
{
    <div class="form-group col-lg-3 col-md-3 col-xs-3">
        <label for="DATA">DATA:</label>
        <input type="text" class="form-control pull-right" name="DATA">
    </div> 
    <button type="submit" class="btn btn-primary pull-right">Get Data</button>
}

推荐答案

好,我阅读了解决方案(

Well, I read the solution (Auto Refresh Partial View). I am posting it, hoping clarify the question:

index.html

<div class="col-lg-12 col-md-12 col-xs-12" id="divPartial">
    @Html.Partial("PartialView", Model)
</div>

<script type="text/javascript">
  $("#buttonForm").click(function(e){
    $('#form').submit();
    $('#divPartial').load('/PartialController/PartialView'); 
  });
</script>

PartialController

public ActionResult PartialView()
{
    // DO YOUR STUFF. 
    return PartialView("PartialView", model);
}

[HttpPost, ValidateInput(false)]
public EmptyResult POSTPartialView(string param1)
{
    // DO YOUR STUFF AFTER SUBMIT.
    return new EmptyResult();
} 

这篇关于如何在其视图中仅刷新部分视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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