のIEnumerableタイプのモデルアイテムを必要とし、私はエラーを取得しています:辞書は、私はLINQので、私のプロジェクトで、MVCに新たなんだ
The model item passed into the dictionary is of type 'System.Boolean', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable`1[Parts.PartsLocation]'.
私はEFでMVCを使用していますので、どのように私は返すんIEnumerable?
ここは私のコントローラである:
public async Task<ActionResult> Index(String aContainer)
{
var container = from x in db.PartsLocations select x;
var empty = from y in db.PartsLocations select y;
if (!String.IsNullOrEmpty(aContainer))
{
var parent = from a in db.PartsLocations
where (a.LocationName == aContainer)
select a.ParentLocation;
return View(await parent.ToListAsync());
}
empty = empty.Where(r => r.LocationName.Contains(null));
return View(await empty.ToListAsync());
}
ビュー:
@model IEnumerable<Parts.PartsLocation>
@{
ViewBag.Title = "Index";
}
モデル:
namespace Parts
{
using System;
using System.Collections.Generic;
public partial class PartsLocation
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
public PartsLocation()
{
this.ManufacturingParts = new HashSet<ManufacturingPart>();
}
public int LocationID { get; set; }
public int TypeID { get; set; }
public string LocationName { get; set; }
public string Description { get; set; }
public int PlantID { get; set; }
public Nullable<int> BayID { get; set; }
public Nullable<int> SecurityGroupID { get; set; }
public Nullable<int> ParentLocation { get; set; }
public Nullable<System.DateTime> LastMoved { get; set; }
public string Notes { get; set; }
public virtual LocationType LocationType { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<ManufacturingPart> ManufacturingParts { get; set; }
public virtual ManufacturingPlant ManufacturingPlant { get; set; }
}
}
モデルコードを投稿できますか? –
申し訳ありません、モデルを編集しました。 –
これは、渡された文字列がnull /空であるシナリオで起こっていますか?これはIEnumerableを満たすリストを返す必要があります。目立つものは、empty = empty.Where(r => r.LocationName.Contains(null))です。これは、空でなければならないようです= empty.Where(r => null == r.LocationName); –