Reputation: 97
I would like to pass object RouteValues
parameter to that button
<div class="wrapper">
<div class="search-box">
<form class="form-inline">
<div class="form-group">
<input type="text" name="searchString" value="@Model.searchString" class="search-text form-control" placeholder="Search..."/>
</div>
<button type="submit" class="btn btn-info">
Search
</button>
</form>
</div>
</div>
I know how to do it with Html.ActionLink, but I don't know where to put it in that button class. Routevalues that I would like to pass look like this:
new { sortOrder = Model.CurrentSort}
Is there any easy way to pass those here to my button?
Upvotes: -1
Views: 1261
Reputation: 1326
@using(Html.BeginForm("action", "controller",
new { sortOrder = Model.CurrentSort }, FormMethod.Post, null){
}
or you can use a hidden field in your form:
<input type="hidden" name="sortOrder" value="@Model.CurrentSort" />
Upvotes: 0
Reputation: 238
If you need submit form use @Html.BeginForm()
:
@Html.BeginForm("NAME_METHOD_FROM_YOUR_CONTROLLER", "FORM_METHOD.POST OR GET")
{
<div class="wrapper">
<div class="search-box">
<form class="form-inline">
<div class="form-group">
<input type="text" name="searchString" value="@Model.searchString" class="search-text form-control" placeholder="Search..."/>
</div>
<button type="submit" class="btn btn-info">
Search
</button>
</form>
</div>
</div>
}
All input in your form will send to your controller.
Another way if you need use form method get, you can change button to <a>
with href attributes: <a href="/Controller_Name/Method/Parameter(optional)" />
the same how your route map.
Upvotes: 0