0
有沒有辦法通過屬性白名單子類?WhiteList子類通過綁定
public class VoteQuestionViewModel
{
[Display(Name = "Vote Question")]
public string Name { get; set; }
public VoteTypeViewModel VoteType { get; set; }
}
public class VoteTypeViewModel
{
public int Id { get; set; }
[Display(Name = "Type of Question")]
public string Type { get; set; }
[Display(Name = "Description")]
public string Description { get; set; }
}
下面將只會工作到白名單類屬性,但它不會工作到白名單子類屬性:
public async Task<IActionResult> Create([Bind("Name, VoteType.Description")] VoteQuestionViewModel voteQuestion)
好點。最後,我擺脫了綁定功能。我創建了專門用於該視圖的附加ViewModel,然後使用AutoMapper來填充最終模型。 – lucas