gpt4 book ai didi

c# - Controller 可以将接口(interface)实例作为参数吗? ASP.NET MVC

转载 作者:太空狗 更新时间:2023-10-29 20:29:24 26 4
gpt4 key购买 nike

ASP .NET Controller 操作方法可以将接口(interface)作为参数之一吗?

我想要这样的东西:

class MyController 
{
[HttpPost]
public ActionResult Action(IMyModel model) {...}
}

这可能吗?显然,我必须告诉框架应该实例化 IMyModel 的哪个具体实现,但是如何实例化?

最佳答案

或多或少everything is extensible in ASP.NET MVC所以是的;那应该是可能的。看看Model Binders ,我想这就是您要找的。

关于c# - Controller 可以将接口(interface)实例作为参数吗? ASP.NET MVC,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2484023/

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