Click here to Skip to main content
15,898,538 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,
After clicking button, dropdown list selected index is going back to '0'. How to maintain to not go to zero in MVC3.
My code is
View is:

HTML
@using (Html.BeginForm())
{
    @Html.ValidationSummary(true)
    <div>
        <div style="float: left">
            States Filter :</div>
        <div style="float: left; padding-removed 20px">@Html.DropDownList("Areas", ViewData["Areas"] as SelectList, "-select state-", new {@style = "width:200px;" })</div>
    </div>
    <div style=" padding-removed30px">
        
            <input type="image" value="submit" src="../../Images/FilterBrowse.gif" alt="submit Button"  />
        
    </div>
    
}
for each loop table(Gridview)


Controller is:
C#
//[Authorize]
        public ActionResult States()//int? id)
        {
            ViewData["Areas"] = new SelectList(am.FindUpcomingStates222().ToList(), "state_Name", "state_Name");
            var state = am.FindUpcomingStates().ToList();
            if (state != null)
            {
                ViewData["name"] = true;
                return View("States", state);
            }
            else
                return View("NotFound");
        }


[AcceptVerbs(HttpVerbs.Post)]
        public ActionResult States(string _stateName, FormCollection formvalues)
        {
            _stateName = Request.Form["Areas"].ToString();
            ViewData["Areas"] = new SelectList(am.FindUpcomingStates222().ToList(), "state_Name", "state_Name", _stateName);
            if (_stateName == "")
            {                
                return View();
            }
            else
            {                
                var state = am.FindUpcomingStates22(_stateName).ToList();
                if (state != null)
                    return View("States", state);
                else
                    return View("NotFound");
            }
        }


Thanks,
Sampath bejugama
Posted

1 solution

Hi there..

As I know you should not use DropDownList. Instead of using this use @Html.DropDownListFor..

Try this..

http://stackoverflow.com/questions/5070762/mvc3-razor-html-dropdownlistfor[^]

All the best.
 
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