【问题标题】:ASP.NET MVC ambiguous action methods signatures and are different using get/postASP.NET MVC 模棱两可的动作方法签名和使用 get/post 不同
【发布时间】:2016-08-14 22:02:35
【问题描述】:

我知道我以前做过这个并且它已经成功了,但是今天当我在我的控制器中创建了两个方法并且得到了..

当前对控制器类型“HomeController”的操作“ContactUs”的请求在以下操作方法之间不明确:

System.Web.Mvc.ActionResult ContactUs() on type HomeController System.Web.Mvc.ActionResult ContactUs(ContactUs) 类型为 HomeController。

这是我的两个与 post/get 不同的地方。

<HttpGet>
Function ContactUs() As ActionResult
Dim objModel As New ContactUsModel

    Return View(objModel)
End Function

<HttpPost>
Function ContactUs(ByVal Model As ContactUs) As ActionResult
    Dim a As String = ""
    Return View(Model)
End Function

我不明白这些怎么可能是模棱两可的,因为它们有不同的签名并且用 post/get 装饰。

【问题讨论】:

  • 您在什么情况下遇到此异常?
  • 如果我只是尝试转到 /home/contactus 的页面,则会收到错误消息。如果我删除第二种方法(发布),页面加载正常。
  • 确保您使用的是 MVC 属性 btw,因为名称完全相同的属性存在于 System.Web.Http 命名空间下。您需要的一次在System.Web.Mvc

标签: asp.net asp.net-mvc vb.net asp.net-mvc-4


【解决方案1】:

安德烈有办法。出于某种原因,它使用了 System.web httppost 和 httpget。所以我不得不用.. 装饰每个方法。

<System.Web.Mvc.HttpPost>

【讨论】:

    猜你喜欢
    • 2010-11-11
    • 2011-08-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-03
    • 1970-01-01
    • 1970-01-01
    • 2021-07-11
    相关资源
    最近更新 更多