【问题标题】:Webgrid not displaying data MVCWebgrid不显示数据MVC
【发布时间】:2015-03-13 05:14:53
【问题描述】:

我正在尝试在 webgrid 中显示模型数据。我看到@grid 中有两行,但没有显示任何内容。即使@grid 中有数据,也无法弄清楚导致这种情况发生的原因。 我试图显示一列只是为了测试,但我也尝试使用@grid.GetHtml() 显示所有列,但 UI 中仍然没有显示任何内容。任何指针表示赞赏!

@model IEnumerable<MyProject.Domain.Entities.Tests>
    @{
        WebGrid grid = new WebGrid(Model);
    }
    <table>
        <tr>
            <td>
             @if (Model.Count() > 0)
            {
               @grid.GetHtml(
               columns:grid.Columns(
               grid.Column(columnName:"Capacity",header:"Capacity")
              ))
            }
            else
            {
               <div>Please select slots and right click on context menu to view attributes.</div>
             }
            </td>
        </tr>
    </table>

【问题讨论】:

  • 我用firebug做了一些调试,令人惊讶的是它显示了post请求中的值
    Slot_Num
    11
    12
    。它没有显示在页面上

标签: model-view-controller webgrid


【解决方案1】:

我解决了这个问题。我将 ajax 数据类型作为 json 并返回部分视图结果。我将ajax post请求中的数据类型更改为html。我还添加了一个新函数 setData(data) 并使用 ajax 请求返回的 html 加载了 div。希望这对可能和我犯同样错误的人有所帮助。

$.ajax({
                    type: "POST",
                    url: "/Home/ViewAttributes1",
                    data: postData,
                    success: function (data) {
                        SetData(data);
                    },
                    **dataType: "html",** (changed from json to html)
                    traditional: true
                });
                **added this function in which I am loading the div with the data returned by ajax**
                function SetData(data)
                {
                        $("#viewAttribs").html(data); // HTML DOM replace
                    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-10-18
    • 2011-11-13
    • 1970-01-01
    • 2018-01-03
    • 1970-01-01
    • 2013-07-03
    • 2011-11-02
    • 2013-09-20
    相关资源
    最近更新 更多