selectlistitem

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

笑着哭i 提交于 2019-12-17 10:43:14
问题 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>

Setting selected property in SelectList for each object in collection based on selected ID in ASP.NET MVC 3

我只是一个虾纸丫 提交于 2019-12-12 05:28:39
问题 Follow up question to : Populate a list property from delimited string The problem I'm having is the DropDown boxes in my Edit view are not retaining/selecting the the proper item based on the AssignedUserID property within BugAssignment model. Models: public class BugAssignment { public int BugAssignmentID { get; set; } public int BugNumber { get; set; } public int? AssignedUserID { get; set; } public virtual User AssignedUser { get; set; } public virtual Status Status { get; set; } public

EntityType 'SelectListItem' has no key defined (Duplicated) - [Key] Is Present

丶灬走出姿态 提交于 2019-12-12 04:06:37
问题 One or more validation errors were detected during model generation: \tSystem.Data.Entity.Edm.EdmEntityType: : EntityType 'SelectListItem' has no key defined. Define the key for this EntityType. \tSystem.Data.Entity.Edm.EdmEntitySet: EntityType: EntitySet 'SelectListItems' is based on type 'SelectListItem' that has no keys defined. public class Country { [Key] [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)] public int Id { get; set; } [Display(Name = "Country Name")] public

View doesn't see class and public static

与世无争的帅哥 提交于 2019-12-11 13:58:50
问题 This is my helper in my View. (I want to list state choices in pulldown). @Html.DropDownListFor(model => model.State, SelectListItemHelper.GetStateList()) I get this error: CS0103: The name 'SelectListItemHelper' does not exist in the current context I put this class in my one and only controller that has all my Create, Edit, Delete Action Results. I made another public class below it. Used this link for my states info: How To Create Select List public class SelectListItemHelper { public

Highlight the selected item in Horizontal List view

孤人 提交于 2019-12-11 09:38:58
问题 By default i need to show one item as highlighted in horizontal list view and when the user selected another item in the horizontal list view i want to highlight that item(removing the earlier and highlight the currently selected) for that i'm trying with the following code,in my adapter Adapter:- int selectedIndex; @Override public View getView(int position, View convertView, ViewGroup parent) { View v = convertView; v = LayoutInflater.from(parent.getContext()).inflate( R.layout.hlist

ASP.NET MVC DropDownListFor does not honour SelectListItem.Selected

ⅰ亾dé卋堺 提交于 2019-12-08 19:42:28
问题 I am using DropDownListFor to render a dropdown list in a view. Somehow the rendered list does not select the SelectListItem with Selected set to true . In the controller action: var selectList = sortedEntries.Select(entry => new SelectListItem { Selected = entry.Value.Equals(selectedValue), Text = entry.Value, Value = entry.Id }); return View(new DropDownListModel { ListId = id, SelectList = selectList, OptionLabel = "Click to Select" }); In the view: <%= Html.DropDownListFor(m => m.ListId,

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

微笑、不失礼 提交于 2019-12-04 06:19:17
问题 This question already has answers here : MVC5 - How to set “selectedValue” in DropDownListFor Html helper (3 answers) Closed 2 years ago . 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

Strongly typed view with a SelectList for DropDownList via ViewData: type mismatch on submit

牧云@^-^@ 提交于 2019-12-03 15:44:54
I am trying to create a form in ASP.NET MVC2 RC 2 that is based on a calendar event object. The object has eventTypeId which is a System.Int32 that I need to populate with via a select list. The controller to create the initial view is: [WAuthorize] public ActionResult AddCalendarEvent() { CalendarEventTypesManager calendarEventTypesManager = new CalendarEventTypesManager(); ViewData["eventTypeId"] = new SelectList( calendarEventTypesManager.SelectAll(), "Id", "Type"); return View(); } The snippet of the View (with the header) is: <%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared

How can I convert an enumeration into a List<SelectListItem>?

ぐ巨炮叔叔 提交于 2019-12-03 01:35:46
问题 i have an asp.net-mvc webpage and i want to show a dropdown list that is based off an enum. I want to show the text of each enum item and the id being the int value that the enum is associated with. Is there any elegant way of doing this conversion? 回答1: You can use LINQ: Enum.GetValues(typeof(MyEnum)).Cast<MyEnum>().Select(v => new SelectListItem { Text = v.ToString(), Value = ((int)v).ToString() }).ToList(); 回答2: Since MVC 5.1, the most elegant way would be to use EnumDropDownListFor method

How can I convert an enumeration into a List<SelectListItem>?

点点圈 提交于 2019-12-02 15:03:19
i have an asp.net-mvc webpage and i want to show a dropdown list that is based off an enum. I want to show the text of each enum item and the id being the int value that the enum is associated with. Is there any elegant way of doing this conversion? SLaks You can use LINQ: Enum.GetValues(typeof(MyEnum)).Cast<MyEnum>().Select(v => new SelectListItem { Text = v.ToString(), Value = ((int)v).ToString() }).ToList(); Since MVC 5.1, the most elegant way would be to use EnumDropDownListFor method of Html helper if you need to populate select options in your view: @Html.EnumDropDownListFor(m => m