【问题标题】:Refresh div data on success method using jquery ajax使用jquery ajax刷新成功方法的div数据
【发布时间】:2013-05-24 11:24:55
【问题描述】:

我正在使用 jquery ajax。 Ajax 调用工作正常,但 div 内的数据没有更新。 OnSuccess 获取整页 html :(

查看(MyDataView.cshtml):

<div id="userGridDiv">
     <a id="lnkName" style="cursor:pointer">Name</a>
    //This div also contain other data....
</div>

@section scripts{
<script type="text/javascript">
    $(document).ready(function () {
      $("#lnkName").click(function () {
            $.ajax({
                url:  '@Url.Action("ShowData", "Controller")',
                type: "POST",
                data: { id: 1, sort: "Name" },
                }
            }).done(function () {

            }).success(function (dv) {
                alert(dv)
            })
            a$.ajaxOptions(
            {
                UpdateTargetId : "userGridDiv",
            })
        });
    });

控制器方法是:

    public ViewResult ShowSata(int id, string data)
    {
           var model = GetDBData(id, data);
           View("MyDataView")
     }

请让我知道我做错了什么。

【问题讨论】:

    标签: jquery c#-4.0 asp.net-mvc-4


    【解决方案1】:

    这样使用:

     public ViewResult ShowSata(int id, string data)
     {
           var model = GetDBData(id, data);
           return PartialView("MyDataView")
     }
    

    【讨论】:

    • 我已转换为部分视图,但仍显示完整的 html。
    • 我创建了一个返回部分视图的新方法,现在它向我显示部分视图 html。谢谢。
    猜你喜欢
    • 1970-01-01
    • 2016-10-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多