-1

I will put a "Choose Civil Status" parameter inside a POST method in my Swagger-UI, so instead of a text fields I wanted it to be a drop down list, I'm using MVC 3, Can anyone explain how can I do that?

here is my sample code..

 [HttpPost]
        public string Generate(string id, Salutation Salutation)
        {
             //code here
        }

1 Answer 1

0

Inside the controller put

var Users = db.TABLENAME;

List<ListItem> list = new List<ListItem> ();
list.Add(new ListItem("Please Select", "0"));
foreach (var item in Users)
{
    list.Add(new ListItem(item.ColName , item.UserId.ToString()));
}

ViewBag.UserList = new SelectList(list, "ValueField", "TextField");

In View

@Html.DropDownList("SomeName", (SelectList)ViewBag.UserList , new { @class = "DropDownList W150 ", value = @ViewBag.SelectedVal }) 

and you will have to declare your ListItem in ModelClasses

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.