After clicking button, dropdown list selected index is going back to '0'. How to maintain to not go

Posted by Sampath1750 under ASP.NET on 3/1/2012 | Points: 10 | Views : 1257 | Status : [Member] | Replies : 1
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:

@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:

//[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




Responses

Posted by: Vuyiswamb on: 3/1/2012 [Member] [MVP] [Administrator] NotApplicable | Points: 25

Up
0
Down
Your problem is flickering that is caused by the Postback,wrap your controls in an Update Panel

Thank you for posting at Dotnetfunda
[Administrator]

Sampath1750, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response