I have a form which on submit passes all input field values as a querystring.
The address i get after submitting is:
http://localhost:51246/Markets?Keyword=keywordhere
The preferred address format is:
http://localhost:51246/Markets/keywordhere
The code for the form:
@using (Html.BeginForm("Index", "Markets", FormMethod.Get, new { id = "login", role = "form", @dataToggle = "validator", @class = "form-horizontal" }))
{
<div class="form-group">
@Html.LabelFor(x => x.Keyword, new { @class = "col-sm-2 control-label" })
<div class="col-sm-10">
@Html.TextBoxFor(x => x.Keyword, new { @class = "form-control", @placeholder = "Enter market or country name..." })
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-primary">Filter</button>
<a href="@Url.Action("Index")" class="btn btn-default">Reset</a>
</div>
</div>
}
My route config is:
routes.MapRoute(
"Markets",
"{controller}/{keyword}/{page}",
new
{
controller = "Markets",
action = "Index",
keyword = UrlParameter.Optional,
page = UrlParameter.Optional
}
);
routes.MapRoute(
"Markets main",
"{controller}/{action}/{id}",
new
{
controller = "Markets",
action = "Index",
id = UrlParameter.Optional,
}
);
...
And the controller is:
[HttpGet]
public async Task<ActionResult> Index(string keyword, int page = 1)
{
//search logic and create viewmodel
Return ActionResult(viewmodel)
}
The functionality works fine, and if i type the preferred format into the address bar and hit enter, the expected search results are displayed.
How can i make the form submit and place the values in the preferred format?