Testing ModelState is always valid in asp.net mvc

后端 未结 7 1136
野趣味
野趣味 2020-12-09 16:29

When testing my controller\'s actions the ModelState is always valid.

public class Product
{
    public int Id { get; set; }

    [Required]
    [StringLengt         


        
7条回答
  •  难免孤独
    2020-12-09 16:57

    Use controller.UpdateModel or controller.TryUpdateModel to use the controller's current ValueProvider to bind some data and trigger model binding validation prior to checking if the ModelState.IsValid

提交回复
热议问题