I'm loading dropdown value database.
My view DropdownDisplay.cshtml
@model RecommendModel
<form asp-controller="Sample" asp-action="MyPostAction" method="post">
@if (ViewBag.ddl2 != null)
{
@Html.DropDownListFor(m => m.ID, ViewBag.ddl2 as SelectList, "Select value", new { @class = "form-control", @required = "required" })
}
<button id="btnSubmit" class="btn btn-pink btn-sm">Submit</button>
</form>
My Controller Recommendation.cs
[HttpGet]
public ActionResult DropdownDisplay(string eID)
{
List<RecommendModel> dropdownlist = new List<RecommendModel>();
dropdownlist = gateway.SelectDomainByCompanyID(CompanyID);
ViewBag.ddl2= new SelectList(dropdownlist , "ID", "Name");
return View();
}
[HttpPost]
[ValidateAntiForgeryToken]
public IActionResult MyPostAction(RecommendModel recommendModel)
{
//posting data and redirecting to same view
return RedirectToAction("DropdownDisplay", "Recommendation");
}
How can keep Selected values after post method and redirected to same view. Also you can suggest another apporach .
