2

我遇到了一个令人困惑的错误,我不太清楚为什么。[HttpPost]通常,当您有两个 ActionResult 并忘记其中一个时,会弹出这种错误。但是正如您所看到的,我 [HttpPost],那么可能导致此问题的原因是什么?

错误:Type 'PersonalWebsite.Controllers.BlogController' already defines a member called 'Search' with the same parameter types Controllers\BlogController.cs

和代码:

//
// GET: /Blog/Search

public virtual ActionResult Search()
{
    return RedirectToAction(MVC.Blog.Index());
}

//
// POST: /Blog/Search

[HttpPost]
[ValidateInput(false)]
public virtual ActionResult Search(SearchViewModel model)
{
    // irrelevant code snipped

    return View(model);
}

Search()此控制器中没有定义其他方法。这很奇怪。

有任何想法吗?

4

2 回答 2

2

您的Search方法已经在另一个partial.

见这里:https ://github.com/Imdsm/PersonalWebsite/blob/master/PersonalWebsite/BlogController.generated.cs

[NonAction]
[GeneratedCode("T4MVC", "2.0"), DebuggerNonUserCode]
public virtual System.Web.Mvc.ActionResult Search()
于 2013-06-25T13:33:12.207 回答
2

您可以通过以下方式为您的方法创建别名:

    [HttpPost]
    [ValidateInput(false)]
    [ActionName("Search")]
    public virtual ActionResult SearchByPost(SearchViewModel model)
    {
        // irrelevant code snipped

        return View(model);
    }
于 2013-06-25T13:34:03.963 回答