2017-06-22 5 views
1

の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; } 
} 
} 
+0

モデルコードを投稿できますか? –

+0

申し訳ありません、モデルを編集しました。 –

+0

これは、渡された文字列がnull /空であるシナリオで起こっていますか?これはIEnumerableを満たすリストを返す必要があります。目立つものは、empty = empty.Where(r => r.LocationName.Contains(null))です。これは、空でなければならないようです= empty.Where(r => null == r.LocationName); –

答えて

-1

aContainerにNOT NULLその後、あなたはリターンを持っている

 a.ParentLocation 
     else PartsLocation List 
を選択

ビューモデル戻り値が異なるので、確認戻り値

+0

こんにちは、「曳航の戻りが違いなので、復帰値を確認する」とはどういう意味か分かりません。説明していただけますか? –

関連する問題