0
我有模式已經得到了,因爲其他兩種型號在網站上用戶可以看到說明和用戶可以發表評論:禁用驗證
public class NoteAndCommentViewModel
{
public Note Note { get; set; }
public Comment Comment { get; set; }
}
public class Note
{
[Required]
public string Title { get; set; }
[Required]
public string Summary { get; set; }
}
public class Comment
{
[Required]
public string Author { get; set; }
[Required]
public string Content { get; set; }
}
我怎樣才能NoteAndCommentViewModel禁用驗證爲所有屬性註釋?因爲現在在動作控制器我的模型始終是無效的,因爲提交表格後,我回到評價模型,注意模型爲空:
[HttpPost]
public ActionResult Create(NoteAndCommentViewModel noteAndCommentViewModel)
{
if (ModelState.IsValid)
{
//.....
}
//.....
}
'如果(ModelState.ContainsKey( 「屬性名」)) 的ModelState [ 「屬性名」] Errors.Clear();' –