selectlistitem

set select value in IEnumerable<SelectListItem> c# mvc [duplicate]

我的未来我决定 提交于 2019-12-02 11:50:16
This question already has an answer here: MVC5 - How to set “selectedValue” in DropDownListFor Html helper 3 answers I have a IEnumerable<SelectListItem> My ViewModel public class StatusClass { public string Status { get; set; } public IEnumerable<SelectListItem> StatusList { get; set; } } I set values in to StatusList from my controller. StatusClass statusObj = new CRM.StatusClass(); List<SelectListItem> Discountdata = new List<SelectListItem>(); Discountdata.Add(new SelectListItem() { Value = "All", Text = "All" }); Discountdata.Add(new SelectListItem() { Value = "Draft", Text = "Draft" });

Asp.Net MVC with Drop Down List, and SelectListItem Assistance

纵饮孤独 提交于 2019-11-27 12:29:12
I am trying to build a Dropdownlist, but battling with the Html.DropDownList rendering. I have a class: public class AccountTransactionView { public IEnumerable<SelectListItem> Accounts { get; set; } public int SelectedAccountId { get; set; } } That is basically my view model for now. The list of Accounts, and a property for returning the selected item. In my controller, I get the data ready like this: public ActionResult AccountTransaction(AccountTransactionView model) { List<AccountDto> accounts = Services.AccountServices.GetAccounts(false); AccountTransactionView v = new