【发布时间】:2019-07-20 10:17:06
【问题描述】:
我想在我的索引控制器中使用连接,以便我的索引视图具有来自规范化表的用户友好数据。
我正在努力用 MVC5 做到这一点,因为它对我来说是新的。下面是我的索引控制器的代码。它不起作用,我知道我缺少某些东西或有什么问题 - 但我不知道是什么。
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Mvc;
using ICS20web.Models;
using Microsoft.Ajax.Utilities;
using Newtonsoft.Json;
using System.Text;
namespace ICS20web.Controllers
{
public class InternalOrdersController : Controller
{
private ICS_Internal_Transactions db = new ICS_Internal_Transactions();
// GET: InternalOrders
public ActionResult Index()
{
var q = from tr in db.ICS_Transactions
join un in db.ICS_Units
on tr.DeliveryUnitID equals un.DeliveryUnitID
join kt in db.ICS_Contacts
on tr.Contact equals kt.LoginID
join sp in db.ICS_Supplies on tr.SuppliesID equals sp.Supplies_ID
select new { sp.ItemDescription, tr.OriginalDate, tr.TransType, tr.LastUpdatedBy , kt.ContactName, tr.OpenClosed, tr.CurrentStatus, tr.CurrentStatusDate, tr.RequsitionNumber, tr.PONumber, tr.DeliveryMonth, tr.DeliveryYear, tr.UnitsOrdered, tr.Emergency, tr.Comments, un.DeliveryUnit, un.PhoneNumber, un.Street, un.City, un.State, un.ZipCode, un.Building, un.Room};
return View(q.ToList());
// return View(db.ICS_Transactions.ToList());
}
这是真正的错误
传入字典的模型项的类型为'System.Collections.Generic.List1[<>f__AnonymousType523[System.String,System.Nullable1[System.DateTime],System.String,System.String,System.String,System.String,System.String,System.Nullable1[System.DateTime],System.String,System.String ,System.String,System.Nullable1[System.Int32],System.Nullable1[System.Int32],System.String,System.String,System.String,System.String,System.String,System.String,System.String,System.String, System.String,System.String]]',但此字典需要类型为“System.Collections.Generic.IEnumerable`1[ICS20web.Models.ICS_Transactions]”的模型项。
【问题讨论】:
-
究竟是什么不工作?您是否遇到任何运行时错误或编译错误?
-
@Stormhashe - 我用(运行时)错误和更多控制器代码更新了我的问题。
-
显示您的视图文件
标签: c#