C# 对控制器类型{x}执行操作{x}的当前请求不明确

C# 对控制器类型{x}执行操作{x}的当前请求不明确,c#,asp.net-mvc,C#,Asp.net Mvc,这是全部错误: The current request for action 'Index' on controller type 'ClientController' is ambiguous between the following action methods: System.Web.Mvc.ActionResult Index(System.String) on type MVCTest.Controllers.ClientController System.Web.Mvc.Actio

这是全部错误:

The current request for action 'Index' on controller type 'ClientController' is ambiguous between the following action methods:
System.Web.Mvc.ActionResult Index(System.String) on type MVCTest.Controllers.ClientController
System.Web.Mvc.ActionResult Index() on type MVCTest.Controllers.ClientController
MVC非常新,我在尝试将搜索栏应用于数据表时不断遇到此错误

控制器:

    public ActionResult Index(string SearchString)
    {
        var Client = from c in db.Clients

                     select c;

        if (!String.IsNullOrEmpty(SearchString))
        {
            Client = Client.Where(s => s.Name.Contains(SearchString));
        }

        return View(Client);
    }
HTML:


@ActionLink(“新建”、“创建”)
@使用(Html.BeginForm())
{

标题:@Html.TextBox(“搜索字符串”)

}

任何人都知道如何解决这个问题,我已经困惑了一段时间。

可能您错过了带有字符串参数的[HttpPost]属性:

通常,您希望Index()操作方法返回视图以响应GET请求。该视图呈现一个表单,该表单将发布到名为Index的操作方法。您希望它以一个字符串参数结束


ASP.NET不知道使用这两种方法中的哪一种。[HttpPost]属性告诉它一个用于POST,另一个用于GET。

用属性装饰您的操作,告诉它是GET操作还是POST操作:

[HttpGet]
  public ActionResult Index()
  {

        return View();
  }  

  [HttpPost]
  public ActionResult Index(string SearchString)
  {
        var Client = from c in db.Clients

                     select c;

        if (!String.IsNullOrEmpty(SearchString))
        {
            Client = Client.Where(s => s.Name.Contains(SearchString));
        }

        return View(Client);
   }

嗯,你有无参数操作
Index()
?谢谢你,总是简单的东西把事情搞砸了。
[HttpGet]
  public ActionResult Index()
  {

        return View();
  }  

  [HttpPost]
  public ActionResult Index(string SearchString)
  {
        var Client = from c in db.Clients

                     select c;

        if (!String.IsNullOrEmpty(SearchString))
        {
            Client = Client.Where(s => s.Name.Contains(SearchString));
        }

        return View(Client);
   }