我正在使用
我在我的应用程序中使用WebGrid
,它告诉我“failEmList”不存在。
以下是调用函数,视图以及从中获取数据的模型部分的代码。
FailEmailSends只是一个List(字符串),并且包含单个电子邮件地址条目的行。
Dim vm As New MassEmailVM
For Each _fail In failEmailSends
vm.failEmList.Add(_fail)
Next
ViewBag.succCount = succCount.ToString
ViewBag.failECount = failEmailCount.ToString
Return View(vm)
查看如下:
@Modeltype xxxxxxxxxxxxx
@Code
ViewData("Title") = "Mass Emails Sent"
End Code
<table>
<tr><th>Total Sent</th><td>@ViewBag.succCount</td></tr>
<tr><th>Total Fail</th><td>@ViewBag.failECount</td></tr>
<tr><th>Fail Email Addresses</th></tr>
</table>
@code
Dim grid = New WebGrid(Model.failEmList)
End Code
<div id="grid">
@grid.GetHtml(
tableStyle:="grid",
headerStyle:="head",
alternatingRowStyle:="alt",
columns:=grid.Columns(
grid.Column("failEmList", "Email List")
))
</div>
视图的相关部分模型:
Private _failEmList As New List(Of String)
Public Property failEmList() As List(Of String)
Get
Return _failEmList
End Get
Set(ByVal value As List(Of String))
_failEmList = value
End Set
End Property
任何想法为什么会抛出以下错误:
System.InvalidOperationException was unhandled by user code
Message=Column "failEmList" does not exist.
Source=System.Web.Helpers
StackTrace:
at System.Web.Helpers.WebGridRow.get_Item(String name)
at System.Web.Helpers.WebGrid.GetTableBodyHtml(IEnumerable`1 columns, String rowStyle, String alternatingRowStyle, String selectedRowStyle)
at System.Web.Helpers.WebGrid.Table(String tableStyle, String headerStyle, String footerStyle, String rowStyle, String alternatingRowStyle, String selectedRowStyle, String caption, Boolean displayHeader, Boolean fillEmptyRows, String emptyRowCellValue, IEnumerable`1 columns, IEnumerable`1 exclusions, Func`2 footer, Object htmlAttributes)
at System.Web.Helpers.WebGrid.GetHtml(String tableStyle, String headerStyle, String footerStyle, String rowStyle, String alternatingRowStyle, String selectedRowStyle, String caption, Boolean displayHeader, Boolean fillEmptyRows, String emptyRowCellValue, IEnumerable`1 columns, IEnumerable`1 exclusions, WebGridPagerModes mode, String firstText, String previousText, String nextText, String lastText, Int32 numericLinksCount, Object htmlAttributes)
at ASP._Page_Views_Admin_MassEmailsSent_vbhtml.Execute() in C:\Users\Skindeep\Documents\Visual Studio 2010\Projects\xxxxxxxxxx\Views\Admin\MassEmailsSent.vbhtml:line 21
at System.Web.WebPages.WebPageBase.ExecutePageHierarchy()
at System.Web.Mvc.WebViewPage.ExecutePageHierarchy()
at System.Web.WebPages.StartPage.RunPage()
at System.Web.WebPages.StartPage.ExecutePageHierarchy()
at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
at System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance)
at System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer)
at System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult)
at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass1c.<InvokeActionResultWithFilters>b__19()
at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation)
InnerException:
答案 0 :(得分:1)
您可以尝试以下方法:
@Code
Dim grid = New WebGrid(Model.failEmList)
End Code
<div id="grid">
@grid.GetHtml(
tableStyle:= "grid",
headerStyle:= "head",
alternatingRowStyle:= "alt",
columns:= grid.Columns(
grid.Column(format:= Function(item) item, header:= "Email List")
)
)
</div>
答案 1 :(得分:0)
试试这个
@grid.GetHtml(
columns: new[] {
grid.Column(format: (item) => item)
}
)
答案 2 :(得分:0)
如果它对某人有帮助,在我的情况下我做了一个复制/粘贴错误,并且在声明网格时忘了更改源代码!一旦我用上面的建议更正了第一列,第二列就抛出了同样的错误。
Dim grid = New WebGrid(Model.WasTheWrongNameHere)