How do you hook up a textbox to a method in MVC5 using attribute routing, with areas?

This is view:

@using (Html.BeginForm())
{                                   
    @Html.TextBox("searchpara")
    @Html.ActionLink("Search", "SearchMethod", "Home", new { area = "Timetables" }, null)                                   
}

Controller:

[RouteArea("Timetables")]
[RoutePrefix("Home")]   
public class HomeController : Controller
{

Method:

[Route("SearchMethod/{searchpara=Test}")]
public ActionResult SearchMethod(string searchpara) 
{

It doesn't work. The problem may not be routing?

有帮助吗?

解决方案

I believe you want a submit button, and not an action link and you may need to update the form to post to a specific action if it is not the current action.

@using (Html.BeginForm("SearchMethod", "Home", new { area = "Timetables" }))
{                                   
    @Html.TextBox("searchpara")
    <button type="submit">Search</button>                                   
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top