开发者

Can I bind to in indexer

Is it possible to bind incoming HTTP data to an indexer.

For example, if I have

[HttpPost]public void Test ([Binding Include="MyProp"]MyClass p) ...

and MyClass defines MyPro开发者_如何学运维p, everything work.

However, what if I want to get additional data that's not defined as a property?

For example, if I have

[HttpPost]public void Test ([Binding Include="MyProp, OtherProp"]MyClass p) ...

and

MyClass has defines an indexer, I'd like the MVC runtime to call

p["OtherProp"] = someValue

Is it possible?


AFAIK there is nothing built in allowing you to achieve this. One way to achieve this would be to write a custom model binder for the MyClass type.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜