c# - IActionResult 误解

标签 c# asp.net-mvc asp.net-core

我刚刚下载了基于 ASP.NET 5 的 music store (microsoft sample projct) 源代码。我不明白为什么 Microsoft 的开发人员在 Controller 中使用 IActionResult 接口(interface)作为返回类型。

使用 IActionResult 接口(interface)的原因是什么? 为什么不直接使用 ActionResult 类型。

enter image description here

最佳答案

请参阅有关 IActionResultActionResult 的帖子:http://forums.asp.net/post/5980446.aspx

IActionResult 允许更广泛的返回类型,包括任何实现 IActionResult 接口(interface)的自定义代码。 ActionResult 仅限于扩展 ActionResult 抽象类的那些类(您也可以使用自定义代码来做,但是使用接口(interface)允许类似多重继承的东西,同时扩展一个类没有)。

关于c# - IActionResult 误解,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33530544/

相关文章:

javascript - 将变量设置为 Google 可视化数据聚合的结果

c# - 在 Asp.Net Core 解决方案发布时转换 app.config 文件?

c# - 网络核心: Do Static Classes need ISerializable from SonarQube?

c# - 将 ref 参数与 this 关键字一起使用?

c# - Unity 广告的 resultCallback 仅在视频完成时奖励

c# - Double.ToString() 的奇怪行为

c# - 上下文菜单中的命令绑定(bind)

asp.net-mvc - 将 mvc3 中的下拉列表绑定(bind)到字典?

asp.net - 覆盖 3.8 中 nopcommerce 插件的默认方法路由

c# - 从授权要求处理程序中的请求正文中读取会破坏路由