0

There are a few questions on SO about multiple submit buttons, such as How do you handle multiple submit buttons in ASP.NET MVC Framework? but what I am having trouble with is having multiple search buttons, each with it's own associated textbox for the value being searched for, and which searches it's own set of data. For example..

    <div class="leftContentColumnRow">
        @Html.TextBox("SearchString", null, new { placeholder = "Search Roles..." })

        <input type="submit" value="" class="searchbtn" name="SearchRoles" />
    </div>

    <div class="rightContentColumnRow">
        @Html.TextBox("SearchString", null, new { placeholder = "Search Permissions..." })
        <input type="submit" value="" class="searchbtn" name="SearchPermissions" />
    </div>

I can determine which button has been clicked, but I am struggling to get hold of the data in both textboxes.

Community
  • 1
  • 1
Fetchez la vache
  • 4,940
  • 4
  • 36
  • 55

2 Answers2

2

Use a separate form for each input button pair with a different action for the form.

Oded
  • 489,969
  • 99
  • 883
  • 1,009
0

Like Oded said, 2 forms, each has it'w own action paramter value.

@using(Html.Beginform("SearchRole","User")
{
    <div class="leftContentColumnRow">
        @Html.TextBox("SearchString", null, new { placeholder = "Search Roles..." })

        <input type="submit" value="" class="searchbtn" name="SearchRoles" />
    </div>
}
@using(Html.Beginform("SearchPermissions","User")
{
    <div class="rightContentColumnRow">
        @Html.TextBox("SearchString", null, new { placeholder = "Search Permissions..." })
        <input type="submit" value="" class="searchbtn" name="SearchPermissions" />
    </div>
}

and the Action methods

public ActionResult SearchRole(string SearchString)
{
  //get data and return something
}
public ActionResult SearchPermissions(string SearchString)
{
  //get data and return something
}
Shyju
  • 214,206
  • 104
  • 411
  • 497
  • I should just comment, make sure you do not nest forms. Nested forms is not legal HTML. (the code above is not nested, I just want to make it clear that this should not be done). – Erik Funkenbusch Aug 24 '12 at 15:46
  • Thanks. That answers my question - the fact I have to work out the results, presumably with some partial views is my problem :) Thanks. MM yep got that thanks. Oded cheers - Shyju fleshed it out by the time I took a look.. – Fetchez la vache Aug 24 '12 at 16:03