How to pass parameter via button

Asked

Viewed 1,726 times

2

How do I use text from @Html.TextBox("pesquisa") as parameter in the code below

<button id="BtnConsulta" onclick="location.href='@Url.Action("Pesquisa", "Cliente", new { PARAMETRO)'"><i class="glyphicon glyphicon-search"></i></button>

</div>
<div class="editor-field">
    @Html.TextBox("pesquisa")
</div><br />

1 answer

4


Make sure your form is using the method GET:

@using (Html.BeginForm("Pesquisa", "Cliente", FormMethod.GET)) 
{ 
    <div>
        <button id="BtnConsulta" name="parametro" value="valor" type="submit">
            <i class="glyphicon glyphicon-search"></i>
        </button>
    </div>
    <div class="editor-field">
        @Html.TextBox("pesquisa")
    </div>
}

Also make sure your button has name, value and be the type submit.

        <button id="BtnConsulta" name="parametro" value="valor" type="submit">
            <i class="glyphicon glyphicon-search"></i>
        </button>

The onclick don’t need.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.