以下是我的视图中的代码。无论出于何种原因,模型属性(即.TableName
)都没有被识别为这样。以下是错误消息:
CS1061: 'PagedList.IPagedList<Monet.Models.FollowUpItems>' does not contain a definition for 'TableName' and no extension method 'TableName' accepting a first argument of type 'PagedList.IPagedList<Monet.Models.FollowUpItems>' could be found (are you missing a using directive or an assembly reference?)
这是视图索引页面的代码。此页面需要返回 SQL 表中的项目列表FollowUpItems
:
@model PagedList.IPagedList<Monet.Models.FollowUpItems>
@{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_Layout.cshtml";
}
@using PagedList.Mvc;
@using PagedList;
<h2>Follow Up Items</h2>
@using (Html.BeginForm())
{
@Html.ValidationSummary(true)
<span id="searchBox" class="boxMe" >
<form method="post">
@Html.DropDownListFor(model => model.TableName, (SelectList)ViewBag.tableID)
@Html.DropDownListFor(m => m.IssueType, (SelectList)ViewBag.issueID)
@Html.DropDownListFor(m => m.Status, (SelectList)ViewBag.statusID)
<input type="image" src="@Url.Content("~/Content/Images/Filter.bmp")" alt="Filter" style="padding-top: 0px;" />
<a href="#" style="padding-left: 30px;"></a>
</form>
</span>
<br />
<br />
<span id="programExplanation" style="width: 500px; float:left; padding: 5px; margin-left: 25px;"></span>
<span class="error" style="clear: both;">
@ViewBag.ErrorMessage
</span>
<span class="msg">
@ViewBag.Message
</span>
<br />
<br />
<br />
}
有问题的下拉列表用作原始项目列表的排序标准。可选择的下拉项目不会反映在数据库中,但是每个代表的特定属性都存在。为了很好的衡量,这里是FollowUpItems
模型
public partial class FollowUpItems
{
public int Id { get; set; }
public string TableName { get; set; }
public string IssueType { get; set; }
public string Status { get; set; }
public string Message { get; set; }
public string CreatedBy { get; set; }
public System.DateTime CreatedOn { get; set; }
public string LastUpdateBy { get; set; }
public Nullable<System.DateTime> LastUpdateOn { get; set; }
public string Key1 { get; set; }
public string Key2 { get; set; }
public string Notes { get; set; }
}
这是来自控制器的代码:
//Sort info
string table = String.IsNullOrWhiteSpace(dropDownSelection["Table"]) ? "%" : dropDownSelection["Table"];
string issue = String.IsNullOrWhiteSpace(dropDownSelection["IssueType"]) ? "%" : dropDownSelection["IssueType"];
string status = String.IsNullOrWhiteSpace(dropDownSelection["Status"]) ? "%" : dropDownSelection["Status"];
//Set dropdown list items based on previous values
var tableOptions = new[] { new { Text = "--Table Name--", Value = "%" }, new { Text = "CE", Value = "AgentContEd" }, new { Text = "AgentProductTraining", Value = "C" } };
var issueOptions = new[] { new { Text = "--Issue Type--", Value = "%" }, new { Text = "Warning", Value = "W" }, new { Text = "Error", Value = "E" } };
var statusOptions = new[] { new { Text = "--Status Type--", Value = "%" }, new { Text = "Open", Value = "O" }, new { Text = "Under Review", Value = "U" } };
ViewBag.tableID = new SelectList(tableOptions, "Value", "Text", table);
ViewBag.issueID = new SelectList(issueOptions, "Value", "Text", issue);
ViewBag.statusID = new SelectList(statusOptions, "Value", "Text", status);