.NET - 从控制器上下文中检索属性?
我有一个控制器 insert
操作:
<AcceptVerbs(HttpVerbs.Post)> _
Function InsertObject(<Bind(Exclude:="Id")> <ModelBinder(GetType(CustomModelBinder))> ByVal object As SomeObject) As ActionResult
End Function
并且我有一个带有 BindModel
实现的 CustomModelBinder
类:
Public Function BindModel( _
ByVal controllerContext As System.Web.Mvc.ControllerContext, _
ByVal bindingContext As System.Web.Mvc.ModelBindingContext) As Object Implements System.Web.Mvc.IModelBinder.BindModel
For Each s In HttpContext.Current.Request.Form.Keys
HttpContext.Current.Response.Write(s & ": " & HttpContext.Current.Request.Form(s) & "<br />")
Next
HttpContext.Current.Response.End()
End Function
如您所见,我有一个 controllerContext
和一个 ModelBindingContext
可用。
如何获取 BindModel
实现中的
部分?
I have a controller insert
action:
<AcceptVerbs(HttpVerbs.Post)> _
Function InsertObject(<Bind(Exclude:="Id")> <ModelBinder(GetType(CustomModelBinder))> ByVal object As SomeObject) As ActionResult
End Function
And i have a CustomModelBinder
class with a BindModel
implementation:
Public Function BindModel( _
ByVal controllerContext As System.Web.Mvc.ControllerContext, _
ByVal bindingContext As System.Web.Mvc.ModelBindingContext) As Object Implements System.Web.Mvc.IModelBinder.BindModel
For Each s In HttpContext.Current.Request.Form.Keys
HttpContext.Current.Response.Write(s & ": " & HttpContext.Current.Request.Form(s) & "<br />")
Next
HttpContext.Current.Response.End()
End Function
As you can see I have a controllerContext
and a ModelBindingContext
available.
How do I get the: <Bind(Exclude:="Id")>
part inside the BindModel
implementation?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我重新实现了这个问题。问题变得过时了。
I reimplemented the issue. Question became obsolete.