0
我可是從數據庫將數據綁定到的WebGrid,我想保持一個ActionLink的編輯的WebGrid的每一行中的一個實例,嘗試下面的一個,但得到的錯誤作爲Object reference not set to an instance of an object
下面的線附近,我的型號名稱是用戶對象引用未設置爲MVC中的WebGrid對象
foreach(var item in Model)
IM還張貼整個代碼
var grid = new WebGrid(source: MvcPopupGrid.Models.User.Users, rowsPerPage: 5);
@grid.GetHtml(
tableStyle: "grid", headerStyle: "gridhead", footerStyle: "paging", rowStyle: "td-dark", alternatingRowStyle: "td-light",
columns:
grid.Columns(
grid.Column(header: "Id", format: @<text><label id="lblId" title="@item.Id">@item.Id</label></text>),
grid.Column(header: "Name", format: @<text><label id="lblName" title="@item.Name">@item.Name</label></text>),
grid.Column(header: "College", format: @<text><label id="lblCollege" title="@item.College">@item.College</label></text>),
grid.Column(header: "PassedOut", format: @<text><label id="lblPassedOut" title="@item.PassedOut">@item.PassedOut</label></text>),
grid.Column(header: "Mobile", format: @<text><label id="lblMobile" title="@item.Mobile">@item.Mobile</label></text>)))
foreach(var item in Model)
{
@item.Id
@item.Name
@item.College
@item.PassedOut
@item.Mobile
@Html.ActionLink("Edit", "UserEdit", new { Id = "@item.Id" }, new { @class = "abookModal", title = "Edit User" })
}
任何對象可能爲空。您應該調試應用程序哪個對象爲null。 –
這個問題需要基本的調試技巧。通過學習自己調試它,你將會變得最好! – usr
真正良好的文章:[精通調試](http://www.codeproject.com/Articles/79508/Mastering-Debugging-in-Visual-Studio-2010-A-Beginn) – Reniuz