gpt4 book ai didi

asp.net-mvc - 自定义模型 Binder MVC 的参数

转载 作者:行者123 更新时间:2023-12-04 20:03:25 24 4
gpt4 key购买 nike

对于下面的代码,我想知道前缀 [] 括号如何影响 Employee 类型

public ActionResult SaveEmployee([ModelBinder(typeof(MyEmployeeModelBinder))]Employee e, string BtnSubmit)
{
// some logic
}

最佳答案

MyEmployeeModelBinder 是一个自定义模型绑定(bind)器,它将在 Employee e 中执行而不是默认模型绑定(bind)器。

public class MyEmployeeModelBinder: DefaultModelBinder
{
public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) {
...
}
}

Employee 类型影响 BindModel() 中的 bindingContext 属性,例如 bindingContext.ModelMetadatabindingContext.ModelType ,其中包含有关模型的信息。查看 ModelMetaData:https://msdn.microsoft.com/pt-br/library/system.web.mvc.modelmetadata%28v=vs.108%29

关于asp.net-mvc - 自定义模型 Binder MVC 的参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32058503/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com