我正在尝试ASP.NET Boilerplate框架,我非常喜欢它,但仍有很多东西需要学习。我不能使以下案例有效。
我有两个相关的实体:Guest
和SocialMedia
CreateGuestViewModel
看起来像这样:
public class CreateGuestViewModel
{
public CreateSocialViewModel SocialMedia { get; set; }
}
View看起来像这样:
<div class="form-group">
<label asp-for="SocialMedia.Twitter"></label>
<input asp-for="SocialMedia.Twitter" class="form-control" placeholder="Enter guest's twitter'" />
</div>
点击“保存”按钮后,在GuestAppService.Create
方法中,SocialMedia
成员为null
。
[AutoMapTo(typeof(Guest))]
public class CreateGuestInput
{
public CreateSocialMediaInput SocialMedia { get; set; }
}
[AutoMapTo(typeof(SocialMedia))]
public class CreateSocialMediaInput
{
public string Twitter { get; set; }
}
我确信我错过了什么。你觉得怎么样?
谢谢, 的Marius
答案 0 :(得分:0)
在html方面,您使用CreateGuestViewModel
和CreateSocialViewModel
作为模型。但是在应用程序服务上,您绑定了CreateGuestInput
和CreateSocialMediaInput
。模型必须相同。