找不到类型或名称空间IHttpActionResult [英] The type or namespace IHttpActionResult not found

查看:304
本文介绍了找不到类型或名称空间IHttpActionResult的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我第一次在ASP.NET MVC4中创建Web API应用程序.我打开了一个新的Web API项目,并添加了一个名为产品"的新控制器.下面给出的函数显示找不到错误的名称空间.

This is the first time I am creating a Web API application in ASP.NET MVC4. I opened a new Web API project and added a new controller named 'Product'. The function given below shows an error namespace not found.

public IHttpActionResult GetProduct(int id) 
{
    var product = products.FirstOrDefault((p) => p.Id == id);
    if (product == null)
    {
        return NotFound();
    }
    return Ok(product);
 }

有人可以帮我解决这个问题吗?

Can anyone help me to solve this problem?

推荐答案

由于使用的是Asp.Net 4.0,IHttpActionResult在Namespace System.Web.Http 4.0版中不可用,因此必须将命名空间更新为5.0版. 0.0.您可以通过右键单击引用中的System.Web.Http命名空间并转到属性来检查您的命名空间版本.您可以通过右键单击您的解决方案项目->管理NuGet解决方案的软件包->来更新它 搜索Asp.Net WebAPI 2->选择Asp.Net WebAPI 2,然后单击管理.您也可以在更新"选项卡上检查它是否可用,如果在更新"选项卡中可用,则可以从那里进行更新.完成此操作后,请转到引用中System.Web.Http命名空间的属性来确认版本.

Since you are using Asp.Net 4.0, IHttpActionResult is not available in Namespace System.Web.Http version 4.0 so you have to update your namespace to version 5.0.0.0. You can Check your namespace version by right click System.Web.Http namespace in references and go to properties. You can update this by Right Clicking on your Solution project->Manage NuGet Packages for Solution-> Search for Asp.Net WebAPI 2 ->Select Asp.Net WebAPI 2 and click Manage. Also you can check if it is available on update tab, if it is available in update tab you can update from there. Once you did that, confirm version by going to properties of System.Web.Http namespace in references.

这对我有用,希望也对您有用.

This works for me and hope will work for you too.

谢谢

这篇关于找不到类型或名称空间IHttpActionResult的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆