开发者

ASP.NET MVC2 - Resolve Parameter Attribute in Model Binder

Given an action like:

开发者_StackOverflow社区
public ActionResult DoStuff([CustomAttribute("foo")]string value) {
  // ...
}

Is there any way to resolve the instance of value's CustomAttribute within a ModelBinder? I was looking at the MVC sources and chances are I'm just doing it wrong, but when I tried to replicate their code which retrieves the BindAttribute for a complex model, calling GetAttributes() did not return the attribute I am looking for.

DefaultModelBinder

GetTypeDescriptor(controllerContext, bindingContext).GetAttributes();


I spoke to Brad Wilson on Twitter and he indicated that this can be achieved with the ModelMetadataProvider in the AspNet4 Futures assembly by implementing the new IMetadataAware interface on the desired types. In addition, he indicated that this functionality would be introduced in MVC 3 for both .NET 3.5 and .NET 4.0.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜