我希望了解如何在控制器接收模型时以一种简洁的方式强制某些属性的值始终为小写或大写。最好使用属性进行操作。
例如:
控制器:
[HttpPost]
public async Task<Model> Post(Model model)
{
//Here properties with the attribute [LowerCase] (Prop2 in this case) should be lowercase.
}
模型:
public class Model
{
public string Prop1 { get; set; }
[LowerCase]
public string Prop2 { get; set; }
}
我听说使用自定义的ValidationAttribute更改值并不是一个好习惯。我还决定创建一个自定义的DataBinder,但是在尝试实现时,我的控制器只返回了null,我不知道该如何正确地实现。
ModelVM
,在构造函数中接受Model
并在那一点上进行转换。然后,在您的控制器中,您可以使用ModelVM
并对其进行必要的操作。 - scgough