Webgrid不显示数据MVC

时间:2015-01-14 21:29:03

标签: model-view-controller webgrid

我正在尝试在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>

1 个答案:

答案 0 :(得分:0)

我解决了这个问题。我把ajax数据类型作为json,我正在返回partialview结果。我将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
                    }
相关问题