【发布时间】:2015-07-15 21:37:29
【问题描述】:
我是使用实体框架的新手。我已经添加了我的模型,我需要在一个视图页面中使用我的两个模型/表格。为此,我将其添加到了我的 AccountViewModels.cs 页面:
public class category_menuitem
{
public Category Category { get; set; }
public MenuItem MenuItem { get; set; }
}
我正在尝试使用这两个模型/表中的值。
我的查看页面:
using System.Data.SqlClient
@model IEnumerable<YourGoGetterV1.Models.category_menuitem>
@{
ViewBag.Title = "Show Menu" - ViewBag.restaurant_id;
}
<h2>ShowMenu</h2>
<div class="jumbotron">
@foreach (var item in Model)
{
<div><strong>@Html.DisplayFor(item1 => item.Category.Name)</strong>
<div>@Html.DisplayFor(item1 => item.Category.Description)</div>
@{
using (var context = new YourGoGetterContext())
{
SqlParameter sa = new SqlParameter("@p0", ViewBag.restaurant_id);
var menu_items = context.MenuItems.SqlQuery("Select * FROM MenuItems where restaurant_id = @p0", sa).ToList();
var test = "DID IT WORK??";
}
}
</div>
}
</div>
控制器:
public ActionResult ShowMenu(string id, int restaurant_id)
{
ViewBag.Id = id;
ViewBag.restaurant_id = restaurant_id;
return View(Models.category_menuitem.ToList((object(id)));
}
我想转换 ID,以便它为传入不同 ID 的内容创建不同的 URL。但是我有两个问题。
1) 我什至不能放入 Models.Category_menuitem.ToList() 因为“方法 'ToList' 没有重载需要 1 个参数”
2)Models.Category_menuitem 不包含 ToList 的定义。
我该怎么办?
【问题讨论】:
标签: c# asp.net-mvc entity-framework model-view-controller