Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have 2 dropdownlists of month and year. here is the razor code.

C#
@using (Html.BeginForm("Index", "Expense", FormMethod.Get))
{
    <p>
        Month <select name="drpMonth">
            @for (var i = 1; i <= 12; i++)
            {

                <option>@i</option>
            }
        </select>
        Year <select name="drpYear">
            @for (var i = -3; i <= 3; i++)
            {
                <option>@(DateTime.Now.AddYears(i).Year)</option>
            }
        </select>
        <input type="submit" value="Filter" />

    </p>
}


when i click on "Filter" button, a postback occurs and the selected value of the dropdownlists are set to default.
How do I maintain a selection in my MVC 5 view's dropdownlist after a postback?
Posted
Comments
Jameel VM 23-Feb-14 23:53pm    
can you post the action result?

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