开发者

Can I bind to in indexer

开发者 https://www.devze.com 2023-03-24 19:18 出处:网络
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) ...

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

精彩评论

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