0
 <div class="form-group">
   <div class="col-md-10"
     @Html.LabelFor(expression: x => Model.MOCType, htmlAttributes: new { @class = "control-label col-md-2" })
     @Html.DropDownListFor(expression: x => Model.MOCType, selectList: new SelectList("CPPSMOC", "SPRDMOC"), optionLabel: "", htmlAttributes: new { @class = "text-danger" })

  </div>
 </div>

Drop down menu code is given above in MVC method of ASP.net but results are not as expected

2 Answers 2

1

If you have a static list, try with below code.

<div class="form-group">
   <div class="col-md-10">
     @Html.LabelFor(x => Model.MOCType, new { @class = "control-label col-md-2" })   
     @Html.DropDownListFor(x => Model.MOCType, new SelectList(
                                              new List<Object>{ 
                                                   new { value = 0 , text = "CPPSMOC"  },
                                                   new { value = 1 , text = "SPRDMOC" }
                                                },"value","text",2),
                                               new { @class = "text-danger" })

  </div>
 </div>

If you have dynamic list then try with below code.

<div class="form-group">
   <div class="col-md-10">
    @Html.LabelFor(x => Model.MOCType, new { @class = "control-label col-md-2" })   
    @Html.DropDownListFor(model => model.MOCType, new SelectList(
              Model.DropdownSelectList, "id", "name", 1), new { @class = "text-danger" })
  </div>
</div>
Sign up to request clarification or add additional context in comments.

Comments

0

The first argument of the SelectList must be IEnumerable, Please pass the custom list (IEnumrable) to the SelectList.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.