I have two controllers and i am passing data one to another. When i pass data second controller to first controller dropdown's selected value disappears. I googled many hours but i failed.How can i keep selected ListItem when user clicks button and after page refreshes? Here is my codes:
First controller which has selectlist and controlling codes.
First Controller:
List<SelectListItem> list= new List<SelectListItem>
{
new SelectListItem { Text = "--- Seçiniz----", Value = ""},
new SelectListItem { Text = "text1", Value = "11"},
new SelectListItem { Text = "text2", Value = "12"},
new SelectListItem {Text = "text3", Value = "13"},
new SelectListItem {Text = "text4", Value = "14"},
new SelectListItem { Text = "text5", Value = "15"}
};
if (TempData["daire"] != null)
{
int daire = Convert.ToInt32(TempData["daire"]);
ViewBag.daire = new SelectList(list, "Value", "Text", TempData["daire"]);
model= (folderBL.getAll().Where(k=>k.Id==daire)).ToList();
}
else
{
ViewBag.daire = new SelectList(list, "Value", "Text","");
model= folderBL.getAll();
}
Second controller, I get the daire value for my SelectList and send data to first controller.
public ActionResult SecondController(string daire)
{
TempData["daire"] = daire;
return RedirectToAction("FirstController");
}
And View.
@using (Html.BeginForm("SecondController","MyDashboard",FormMethod.Post))
{
@Html.DropDownList("daire", (SelectList)ViewBag.daire, new { id = "mydrop" })
<td><input type="submit" value="Send" />
}