2012-04-09 10 views
1
// HomeController.cs 
[AutoMap(typeof(Test), typeof(TestViewModel))] 
public ActionResult Index() 
{ 
    var tests = new List<Test>(); 
    tests.Add(new Test()); 
    return View(tests); 
} 

// Index.cshtml 
@model IEnumerable<AutoMapperTest.Models.TestViewModel> 

// AutoMapper Configuration 
CreateMap<Test, TestViewModel>(); 

// Automapper configuration test is fine 
[TestMethod] 
public void Should_map_dtos() 
{ 
    AutoMapperConfiguration.Configure(); 
    Mapper.AssertConfigurationIsValid(); 
} 

AutoMapAttributeここから取得します。Automapper:タイプマッピングの設定がないか、サポートされていないマッピング

アクションが「テスト」を返した場合、それは機能します。それが 'IEnumerable'を返す場合(TestViewModelとIEnumerableが明白に期待されるように変更されたビュー)。私は間違って何をしていますか?私が理解していることから、List型を明示的にマップする必要はありません。

これはおそらく簡単な回答ですが、これを動作させるために過去2時間を費やしていますので、誰かが私に解決策を教えてくれてありがとうと思います。

答えて

2

それはあなたがリストかどうかを含めてAutoMapper属性を変更するかどうかをあなたの説明から私にははっきりしていない:

[AutoMapper(typeof(List<Test>), typeof(List<TestViewModel>)] 
+0

私はそれがこのような愚かな何かを知っていました。私は、属性がリストを含む必要はないと仮定しました。どうもありがとう。 – NVM

関連する問題