简体   繁体   English

MVC Ajax编辑按钮从局部视图重新渲染其他局部视图

[英]MVC Ajax Edit button from partial view to re render other partial view

So I have 2 partial views in my main view: A gridView and a roundPanel . 所以,我有2点partial views在我的主要观点:一个gridView和一个roundPanel

So when the "Edit" button in my Gridview row is hit, the roundPannel should update with the info of the row. 因此,当单击我的Gridview行中的“编辑”按钮时, roundPannel应该使用该行的信息进行更新。

My Edit button: 我的编辑按钮:

Ajax.ActionLink("Edit", "EditConfig", new { id = DataBinder.Eval(c.DataItem, "QueueMonitorConfigurationsID") }, new AjaxOptions { UpdateTargetId = "configs" })

The function it calls: 它调用的函数:

[HttpGet]
public ActionResult EditConfig(int id)
{
    StorageConfigurationModel resultForPanel = new StorageConfigurationModel { };
    IEnumerable<StorageConfigurationModel> configList = (IEnumerable<StorageConfigurationModel>)Session["ConfigurationList"];
    foreach (StorageConfigurationModel configModel in configList)
    {
        if (configModel.QueueMonitorConfigurationsID == id)
        {
            resultForPanel = configModel;
            break;
        }
    }
    return PartialView("cbpnlNewUpdateConfigs", resultForPanel);
}

Every time I click "Edit", a new view is open, when I just want to refresh the roundPanel ( partialview ). 每当我只想刷新roundPanelpartialview )时,每次单击“编辑”都会打开一个新视图。

I call my controller through an ajax call 我通过ajax呼叫给控制器打电话

$.ajax({
    url: "@(Url.Action("Action", "Controller"))",
    type: "POST",
    cache: false,
    async: true,
    data: { data1: 'data1' },
    success: function (result) {
        $(".Content").html(result);
    }
});

Doing it this way I replace the contents of a div with the partial view that is returned from the controller. 这样,我将div的内容替换为从控制器返回的局部视图。 I don't know if it will make a difference but my method for the partial view I return PartialViewResult instead of ActionResult. 我不知道这是否会有所作为,但我对部分视图的方法返回PartialViewResult而不是ActionResult。 Hopefully this helps. 希望这会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM