【问题标题】:Reload PartialView from itself INSIDE从内部重新加载 PartialView
【发布时间】:2013-08-06 07:34:02
【问题描述】:

嗯,

我有一个 PartialView,它生成一个带有复杂模型的 VIEW。 我有一个按钮,我想完全重新生成我的 PartialView

    @if (!Model.editFlag)
{
<button id="EditButton" class='btn btn-small'>Edit</button>
}
else
{
<button  class='btn btn-small'>Update</button>
}

这是我的 Ajax CALL

    $.ajax(
{
    type: "POST",
    url: "@Url.Action("DeviceDetails_Edit","DeviceLayout")"  ,
    data:
    {
        DeviceID: '@Model.DeviceID',
        DeviceName: '@Model.DeviceName',
        DeviceDescription: '@Model.DeviceDescription',
        editFlag: '@Model.editFlag',
    },
    cache:false,
    success: function(html) 
        { 
            alert('success');
        },
        error: function(e) 
            { 
            alert("errorn"); 
            }

});
});

从控制器,我有一个 ActionResult ,它返回一个带有我的新特定模型的部分视图 return PartialView("_DeviceDetails", model);

进入我的视野,存在更多的PartialView`s

我该如何解决这个问题?

【问题讨论】:

  • 你说的是什么意思:“在我看来,存在更多的partialViews”,问题或错误是什么?
  • 这方面并不重要(我的页面中有更多的 PartialView),我想要的是在我按下按钮时从另一个操作中完全重新加载我的部分视图
  • 感谢费利佩·奥里亚尼!
  • 记得检查我的答案是否对你有帮助:)

标签: jquery asp.net-mvc


【解决方案1】:

我假设您的页面上已经有一个 div。使用 jQuery,您可以在单击事件按钮中清除 div 元素,以供示例

<div id="myView"></div>

使用jquery,可以用empty方法清除div:

$("button").click (function (e) {

   // clear the html on the  div
   $("#myDiv").empty();


    // make a post to reload the div:
    $.ajax(
    {
        type: "POST",
        url: "@Url.Action("DeviceDetails_Edit","DeviceLayout")"  ,
        data:
        {
            DeviceID: '@Model.DeviceID',
            DeviceName: '@Model.DeviceName',
            DeviceDescription: '@Model.DeviceDescription',
            editFlag: '@Model.editFlag',
        },
        cache:false,
        success:function(html) 
                { 
                    // fill the div with the html returned by action
                    $("#myView").html(html);
                },
        error:  function(e) 
                { 
                    alert("errorn"); 
                }
    });   

});

【讨论】:

  • 它是外部视图。但是如何从该局部视图重新加载局部视图?
  • 在这个局部视图中添加一个 javascript 来加载另一个。看看 javascript (jquery) 代码。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-06-25
  • 1970-01-01
  • 2012-10-20
  • 1970-01-01
  • 2020-08-20
  • 1970-01-01
相关资源
最近更新 更多