Click here to Skip to main content
15,890,123 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I am new to mvc4 . can anyone Help me the in how to bind webgrid based on filter conditions from textbox input and dropdownList selected value. For eg : If textbox has Floor name like "F1" and if dropdownList selected value is "vacant" then i need to show in gridview the list of all seats which are vacant in that particular floor.If he selected "Blocked" from dropdown I should display all the seats which are blocked in that floor. Please help me.
Posted
Updated 22-May-14 21:12pm
v3

1 solution

You can see the following link for searching, filtering and sorting in mvc4 grid data

http://www.asp.net/mvc/tutorials/getting-started-with-ef-using-mvc/sorting-filtering-and-paging-with-the-entity-framework-in-an-asp-net-mvc-application

For dropdown selected index you have to use jquery

XML
@Html.DropDownListFor(model => model.StateID, Enumerable.Empty<SelectListItem>(), "--Select State--")

<script type="text/javascript">
    $('#CountryID').change(function () {
        var selectedCountry = $(this).val();
        if (selectedCountry != null && selectedCountry != '') {
            $.getJSON('@Url.Action("GetStates")', { CountryID: selectedCountry }, function (states) {
                var statesSelect = $('#StateID');
                statesSelect.empty();
                statesSelect.append($('<option/>', {
                    value: 0,
                    text: '--Select State--'
                }));
                $.each(states, function (index, state) {
                    statesSelect.append($('<option/>', {
                        value: state.value,
                        text: state.text
                    }));
                });
            });
        }
    });
</script>

public ActionResult GetStates(int CountryID)
        {
            List<State> states = db.States.Where(a => a.CountryID == CountryID).ToList();
            return Json(
                states.Select(x => new { value = x.StateID, text = x.StateName }),
               JsonRequestBehavior.AllowGet);
        }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900