asp.net mvc-视图的Ajax刷新foreach元素 [英] asp.net mvc - Ajax refresh foreach element of a View

查看:49
本文介绍了asp.net mvc-视图的Ajax刷新foreach元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

希望在退出jquery对话框后ajax/刷新当前页面.

wish to ajax/refresh the current page after quitting a jquery dialog.

我有一个包含foreach循环的View,数据是从模型中下拉的,每个循环有2个按钮edit/Delete.当我单击编辑按钮"时,将打开一个jquery UI对话框进行编辑,当我保存jquery对话框时,我想要的是退出对话框后对视图的数据进行Ajax/刷新(特别是编辑后的数据) ).

I am having a View which contains a foreach loop, the data is pulled down from a model, there are 2 buttons edit/Delete for each loop. When I click on the 'edit button', a jquery UI Dialog is opened for editing, when I save the Jquery Dialog, what I want is to Ajax/Refresh the datas of the View after quiting the dialog (especially the edited datas of course).

我该如何实现?

谢谢

这是我的观点

@{
    foreach (var item in Model) {
        <tr>
            <td>
                @Html.DisplayFor(modelItem => item.IdPhoto)
            </td>
            <td>
                @Html.TextAreaFor(modelItem => item.Date)
            </td>
            <td>
                @Html.TextAreaFor(modelItem => item.Nom)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Category)
            </td>
            <td>
                @Html.CheckBoxFor(modelItem => item.Actif)
            </td>
            <td>

            <button class="Edit" value="@item.IdPhoto">Edit</button> 
            <button class="Delete" value="@item.IdPhoto">Delete</button> 

            </td>
        </tr>
    }
}

推荐答案

我的建议是使用jQuery从部分视图中加载要编辑/删除的信息. 然后,您可以从jQuery对话框中进行编辑/删除,完成后,只需再次使用jQuery重新加载该局部视图即可.

My suggestion is to load the information you want to edit/delete from a partial view using jQuery. Then you can edit/delete from your jQuery dialog and when you are done, just reload that partial view using jQuery once again.

您视图中的代码将类似于以下内容:

The code on your view would be something along the lines of:

$(document).ready(function () {

    LoadInfo(); //Loads partial view

});

function LoadInfo() {

    $.get("MyAction", { param1 : myParameter }, function (data) {

        $("#mydata").empty();
        $("#mydata").html(data);
    });
}

在您的控制器中:

    [HttpGet]
    public virtual ActionResult MyAction(parameters)
    {
        var query = GetMyDataModel();

        return PartialView("_MyPartialViewName", query);
    }

完成编辑/删除后,可以再次调用LoadInfo(),它将重新加载页面的该部分.

And when you are done editing/deleting, you can call LoadInfo() once again and it will reload that part of your page.

希望这会有所帮助.

这篇关于asp.net mvc-视图的Ajax刷新foreach元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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