【问题标题】:How to Reloading a partial view from the view?如何从视图重新加载部分视图?
【发布时间】:2014-04-17 12:48:53
【问题描述】:

在我的 ASP.NET MVC 项目中,我遇到以下情况:

具有此操作的 ExController:

public ActionResult Index()
{
   //Get Data from Repository
   return View(Model);
}

在 Ex View 中,我有一个 Index.cshtml 和一个 _PartialIndexGrid.cshtml。

在索引中,我有一个带有复选框的功能区菜单,当我单击它时,我只想刷新放置在 _PartialIndex.cshtml 上的网格,这可能吗?

索引视图:

 //Ribbon Code here
  @Html.Partial("_PartialIndexGrid", Model)

 <script>
 if (e.parameter) {
            $.ajax({
                url: '@Url.Action("Index")',
                type: "get",                    
                success: function (result) {
                    $("_PartialIndexGrid").html(result);
                },
                failure: function () {
                    alert('error');
                }
            });
 </script>

此脚本实际上执行 ajax 请求,但不会重新加载网格局部视图。 谢谢。

【问题讨论】:

  • 您是否将@Html.Partial("_PartialIndexGrid", Model) 包裹在某个 div 中?
  • @Satpal 不,它不在 div 或其他东西中

标签: javascript jquery asp.net asp.net-mvc razor


【解决方案1】:

创建一个容器 div 并在复选框更改时检查它是否通过 ajax 调用重新加载部分视图,如下所示:

<div id="PartiaContainer">

 @Html.Partial("_PartialIndexGrid", Model)



</div> 

<input  type="checkbox" id="checkbox1"/>

<script>


$('#checkbox1').change(function(){

            if(this.checked)
            {
            $.ajax({
                url: '@Url.Action("Index")',
                type: "get",                    
                success: function (result) {
                    $("#PartialContainer").html(result);
                },
                failure: function () {
                    alert('error');
                }
            });
}
});
 </script>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-10-31
    • 1970-01-01
    • 1970-01-01
    • 2014-05-12
    • 1970-01-01
    • 1970-01-01
    • 2015-01-01
    • 1970-01-01
    相关资源
    最近更新 更多