您好:我有一个正在使用asp.net mvc的Web应用程序,唯一的问题是我正在创建一个来自数据库的下拉列表。当我运行它时,下拉菜单中没有任何显示。有人告诉我这个问题是一个绑定选择标签,而不是绑定到选择列表,尽管我似乎无法弄清楚。这是我到目前为止所看到的,这是我在手表1上遇到的错误:错误CS0103:名称“模型”在当前上下文中不存在
Index.cshtml:
@model RiskApplication.Models.RiskApplicationModel
@{
ViewBag.Title = "Index";
}
<h2>RiskPrescreen Application 2018</h2>
<p>
@Html.ActionLink("Create New", "Create")
</p>
<p>
@Html.ActionLink("Help", "ViewPage1")
</p>
<form asp-controller="DataForms" asp-action="Index" method="get" runat="server">
<p>
<select asp-for="Department" asp-items="@Model.owners">
<option value="">-----------</option>
</select>
Application Name: <input type="text" name="SearchString">
<input type="submit" value="Search" />
</p>
</form>
DataFormsController.cs:
public async Task<ActionResult> Index(string department, string searchString)
{
// Use LINQ to get list of genres.
IQueryable<string> genreQuery = from m in db.AppOwner_DD
orderby m.AppOwnerDes
select m.AppOwnerDes;
var dataForms = from m in db.DataForms
select m;
if (!String.IsNullOrEmpty(searchString))
{
dataForms = dataForms.Where(s => s.Name.Contains(searchString));
}
if (!String.IsNullOrEmpty(department))
{
dataForms = dataForms.Where(x => x.AppOwner_DD.AppOwnerDes == department);
}
var movieGenreVM = new RiskApplicationModel();
var list = await genreQuery.Distinct().ToListAsync();
movieGenreVM.owners = new SelectList( list );
movieGenreVM.dataForms = await dataForms.ToListAsync();
return View(movieGenreVM);
}
RiskApplicationModel.cs:
using System.Collections.Generic;
//using Microsoft.AspNetCore.Mvc.Rendering;
using System.Web.Mvc;
namespace RiskApplication.Models
{
public class RiskApplicationModel
{
public List<DataForm> dataForms;
public SelectList owners;
public string department { get; set; }
}
}
如果有人可以提供帮助,将不胜感激!谢谢