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時間を費やしていますので、誰かが私に解決策を教えてくれてありがとうと思います。
私はそれがこのような愚かな何かを知っていました。私は、属性がリストを含む必要はないと仮定しました。どうもありがとう。 – NVM