Question

I have a form in my razor view which works exactly as it should. I select values from the drop down and press the submit button and it return to me a paginated set of results. All well and good.

@using (Html.BeginForm())
    {
        int index = 0;
        foreach (var type in @Model.AttributeTypes)
        {
            @Html.DropDownListFor(m => m.SelectedAttributeValueIds[index], Model.AttributeValuesList[Convert.ToInt32(@type.Value)], "Filter by " + type.Text)
            index++;
        }

        <input type="submit" value="Filter"/>
}

The problem is that at the bottom of the page, outside of the form I want a Show all button/link. Pressing this button should essentially do the same thing that the above submit button does. In other words I'd like this Show all button to show all of the results of the last query (or the currently selected values in the dropdowns - not too bothered which) without pagination. I can do the no pagination bit, that is easy. What I want to know is how will my button/link get the values from the dropdown from outside of the form and submit that form?

Was it helpful?

Solution

You can use javascript/jquery to submit the form on click of that button.

$('#formId').submit();

To wire this up you could do the following on your document ready script:

$('#buttonId').click(function() {
  $('#formId').submit();
});

OTHER TIPS

Use javascript to read information on the dom element you need to grab the info and them submit an ajax request.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top