In my code, I have a specific condition coming in from the Model to determine whether I am in create mode or edit mode. If I find myself in Edit mode, I need to ensure that the dropdownlist shows the last saved value. However, if I am in create mode, the dropdownlist should default to a predefined value.
*.ASCX
<% if(Model.isCreate == true)
{
Html.DropDownList("myOptionListName",
new SelectList(ViewBag.MyOptions, "Id", "Name"),
Resources.Global.DefaultMenuItem,
new { style = "width:200px" });
}
else
{
Html.DropDownList("myOptionListName",
new SelectList(ViewBag.MyOptions, "Id", "Name",
ViewBag.LastSavedOption),
new { style = "width:200px" });
}%>
It is crucial for me to use the name "myOptionListName" due to other JavaScript functions referencing it. Unfortunately, at the moment, the current code does not render the dropdown at all.
How can I modify the code to display the menu based on the conditional check while keeping the same name for consistency?