Reputation: 778
i am trying to redirect to another action within the same controller action is called index
[HttpGet]
public ActionResult Search(string city)
{
return RedirectToAction("Index", "Rentals", new { CityName = city });
}
this is index action
[HttpPost]
public ActionResult Index(String CityName)
{
}
am i missing something?
Upvotes: 1
Views: 3897
Reputation:
Please change HttpPost
to HttpGet
[HttpGet]
public ActionResult Index(String CityName)
{
}
Because whenever you call the Action, then the GET
method will be first called.
Upvotes: 0
Reputation: 432
As the two actions are in the same controller, you could call the Index
method directly from Search
like this:
return Index(city);
not necessarily to user the RedirectToAction
method.
Upvotes: -1
Reputation: 24332
You are trying to redirect action which is searching for a matching action but in this case there is no get action, so you have to add a get method to accept redirect. If you want, you can check the HTTPGET or POST inside the method
[HttpPost]<---- Remove this
public ActionResult Index(String CityName)
{
}
Upvotes: 3