开发者

Problem displaying a webgrid in MVC pertial view

I already a have a view. Now I have to add a new web grid in that view. To do this, I have create a partial view and trying to bind a webgrid in the partial with no success. :(

This is my controller:

public ActionResult RegisteredUsers()
    {
        var query = from p in dc.UserProfile
                    select new RegisterModel()
                    {
                        UserName = p.Name
                    };

        List<RegisterModel> users = query.ToList();

        return View(users);
    }

This is my partial view:

<%
    var grid = new WebGrid(Model,rowsPerPage:5);
    %>
    <%: 
       grid.GetHtml(
                    tableStyle: "wGrid",
                    headerStyle: "wGridHeader",
                    alternatingRowStyle: "alt",
                    footerStyle: "wGridFooter",
                    columns: grid.Columns(

                    grid.Column("UserName","User name")

                  )
               )
    %>

BUT, it shows an error in the webgrid in my partial view. the error is : A data source must be bound before this operation can be performed.

The err开发者_运维百科or is self explanatory. But the 'Model' in the line "var grid = new WebGrid(Model,rowsPerPage:5);" is the datasource. Isn't it?? Guys any idea how to solve this??


I'm not sure in the aspx way but using Razor at the top of the partial view you have to declare something like this @model <namespace of model>.<modelname> since you are passing a list then you'd need @model IEnumerable<namespace of model>.RegisterModel.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜