- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我已经创建了一个 View ,我想用它来显示从数据库中提取并在我的操作中传递给 View 的结果。当我创建 View 时,我没有告诉它我想传入哪些对象,所以我尝试手动添加它们,但 View 似乎无法识别它们。
这是我的结果 View ,顶行是我要添加的内容,但 VS 无法识别它。所以空格是红色的(无法识别),item.Name 和 item.description 是红色的
@spaces IQueryable<GiftExchange.Core.Models.Space.YogaSpace>
@{
ViewBag.Title = "Results";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h3>Search Results</h3>
@using (Html.BeginForm("Results", "Home", FormMethod.Get))
{
<p>
@Html.TextBox("Location") <input value='Search' type="submit" />
</p>
}
<table border="1">
<tr>
<th>
@Html.DisplayNameFor(spaces => spaces.Name)
</th>
<th>
@Html.DisplayNameFor(spaces => spaces.Description)
</th>
</tr>
@foreach (var item in spaces)
{
<tr>
<th>
@Html.DisplayFor(modelItem => item.Name)
</th>
<th>
@Html.DisplayFor(modelItem => item.Description)
</th>
</tr>
}
</table>
这是我的 Action
[AllowAnonymous]
public ActionResult Results(string searchTerm)
{
IQueryable<YogaSpace> spaces;
using (var repo = new YogaSpaceRepository())
{
spaces = repo.All;
}
return View(spaces);
}
最佳答案
在 View 的第一行,将 @spaces
切换为 @model
。
然后在您想使用它的地方,使用 Model
而不是 spaces
。
有关更多详细信息,请在谷歌上搜索“强类型 View ”。
关于c# - 我如何让我的观点识别我的对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28097605/
Closed. This question is opinion-based。它当前不接受答案。
我有一个项目需要在工作和在家中使用两台不同的计算机进行。 我需要能够在两台计算机上都处理代码,所以问题有两个。 共享代码 共享工作空间。 用svn 1很简单;但是我感到很讨厌将损坏的代码提交给svn,
我正在尝试在 Eclipse 中实现 coreNLP 情绪分析器。得到错误: Unable to resolve "edu/stanford/nlp/models/lexparser/englishP
我有一个输入框: 如果我在输入字段中输入 .75 ,则应在 .75 之前自动添加 0 ,使其变为 0.75 此外,如果我输入 1.3 那么它应该变成 1.30 我已经尝试过: echo "
我有一个带有以下行的父组件 根据上下文,它呈现路由器配置中定义的两个组件之一 path: 'parent', component: Parent, children: [ {
我安装了最新的 angular-ui-select (v0.12) 和 angular v1.2.27。我的页面无法加载。我得到: expected expression, got . (a poin
我是一名优秀的程序员,十分优秀!