-1

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?

Piotr P
  • 67
  • 1
  • 2
  • 11
  • What do you mean _to the button_? Your subitting a `form` so it needs to be in the forms `action` attribute. Use the `@Html.BeginForm()` method. –  Sep 01 '16 at 10:08
  • if you know how to use it in Html.ActionLink , can't you create a Html.ActionLink with bootstrap css and display it as a button? – Emil Sep 01 '16 at 10:55

2 Answers2

0

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.

Perdido
  • 238
  • 3
  • 12
0
    @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" />
Ankit Sahrawat
  • 1,306
  • 1
  • 11
  • 24