2016-04-21 63 views
0

我知道我已經做到這一點,它的工作,但今天當我創造了我的控制器兩種方法和我得到..ASP.NET MVC曖昧的動作方法的簽名和不同使用GET/POST

採取行動的當前請求「聯繫我們」上控制器類型「的HomeController」是以下動作的方法之間曖昧:

System.Web.Mvc.ActionResult聯繫我們()上式的HomeController System.Web.Mvc.ActionResult聯繫我們(聯繫人)在類型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裝飾。

+0

在什麼情況下你會得到這個異常? – Andrei

+0

如果我只是嘗試訪問/ home/contactus的頁面,我會收到錯誤消息。如果我刪除第二種方法(後),頁面加載罰款。 –

+2

請確保您使用的是MVC屬性btw,因爲具有完全相同名稱的屬性存在於'System.Web.Http'命名空間下。一旦你需要在'System.Web.Mvc'中 – Andrei

回答

0

安德烈有解決方案。出於某種原因,它使用System.web httppost和httpget。所以我不得不用裝飾每種方法..

<System.Web.Mvc.HttpPost>