ASP.NET MVC 4 - WebGrid - 必须绑定数据源才能执行此操作

时间:2014-09-25 11:42:53

标签: asp.net-mvc-4 webgrid

我是ASP.NET MVC 4的新手。我正在尝试创建一个基本的WebGrid来尝试学习它是如何工作的。目前,我有以下代码:

模型

public class UserAccountSummaryCollectionModel 
{
    public IEnumerable<UserAccountSummaryModel> UserAccountSummary { get; set; }
    public PagingInfo PagingInfo { get; set; }
    public int user_pk { get; set; }

}

控制器

  public ActionResult AddSitesToUser(string returnUrl="", int userId = 0, string siteName = "", string businessIdentifier = "", int pageSize = 10, int page = 1)
    {

        ViewBag.returnUrl = returnUrl;
        ViewBag.nameVal = siteName;
        ViewBag.identifierVal = businessIdentifier;
        var view = new UserAccountSummaryCollectionModel();

        try
        {
            var data = _userAccount.GetAllFilteredCustomers(userId, true, siteName, businessIdentifier, _pageSize, page);

            if (data != null)
            {
                view = new UserAccountSummaryCollectionModel { user_pk = userId, PagingInfo = new PagingInfo { CurrentPage = data.currentPage, ItemsPerPage = data.PageSize, TotalItems = data.totalRecordSize, TotalPages = data.numberOfPages }, UserAccountSummary = data.pagedSet };
            }
        }
        catch (Exception ex)
        {
            _logger.Error(ex.Message, ex);
            throw ex;
        }

        return View(view);
    }

查看:

@model PACT.UI.Models.UserAccountSummaryCollectionModel    
@{    
        ViewBag.Title = "Add Sites To User";    
        Layout = "~/Views/Shared/_Layout.cshtml";    
        var grid = new WebGrid(Model.UserAccountSummary, rowsPerPage: 20);    
    }    
 <div id="gridcontent">    
           @grid.GetHtml(tableStyle: "webGrid",    

我只是想在不必连接数据库的情况下了解WebGrid。 感谢

0 个答案:

没有答案