简体   繁体   English

C#:为什么我的控制器不能识别 [HttpGet]?

[英]C#: Why won't my controller recognize [HttpGet]?

I am using visual studio 2008 MVC Application.我正在使用 Visual Studio 2008 MVC 应用程序。

I want to use [HttpGet] and [HttpPost] for two methods w/ same name.我想将 [HttpGet] 和 [HttpPost] 用于两个具有相同名称的方法。


[HttpGet]
public ViewResult RsvpForm()
{
    return View();
}

[HttpPost]
public ViewResult RsvpForm(GuestResponse guestResponse)
{ 
    //To do: Email guestresponse
    return View("Thanks", guestResponse);
}

I get this error:我收到此错误:

Error 2 The type or namespace name 'HttpGetAttribute' could not be found (are you missing a using directive or an assembly reference?)错误 2 找不到类型或命名空间名称“HttpGetAttribute”(您是否缺少 using 指令或程序集引用?)

But I imported the following:但我导入了以下内容:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using PartyInvites.Models;
using System.Net;
using System.IO;
using System.Text;
using System.Web.Mvc.Resources;
using System.Web.Mvc.Html;
using System.Web.Mvc.Ajax;

You are using an older version of MVC.您使用的是旧版本的 MVC。

Use:使用:

  [AcceptVerbs(HttpVerbs.Get)]

instead相反

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM