selectlist

MVC DropDownList selected value not working

人盡茶涼 提交于 2019-12-05 03:06:06
I am using MVC 5. I have my ViewBag for list as ViewBag.TitleList = new SelectList((new string[] { "Mr", "Miss", "Ms", "Mrs" }), contact.Title); //contact.Title has selected value. then I tried converting the array to SelectListItem ( to no avail) On the View it looks like @Html.DropDownListFor(model => model.Title, ViewBag.TitleList as SelectList, "Select") also I tried @Html.DropDownList("Title", ViewBag.TitleList as SelectList, "Select") The list loads successfully but the Selected Value is Not selected . How to Fix this problem? Update The culprit was ViewBag.Title matching my model.Title.

Combine 2 fields in SelectList

怎甘沉沦 提交于 2019-12-03 20:58:09
Currently I have SelectList that writes ID, and shows FirstName on the form. ViewBag.Person = new SelectList(db.Person, "ID", "FirstName"); How to concatenate FirstName and LastName into SelectList? Something like: ViewBag.Person = new SelectList(db.Person, "ID", "FirstName & LastName"); Try something like this: ViewBag.Person = new SelectList((from s in db.Person select new { ID=s.ID, FullName = s.FirstName+ " " + s.LastName}), "ID", "FullName", null); Or Add a new property to your Person model public string Fullname { get { return string.Format("{0} {1}", FirstName, LastName); } } 来源: https:

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

Drupal 7: Best Practice for a Dynamic Select List in Drupal 7

十年热恋 提交于 2019-12-03 05:21:33
问题 What is the best practice for a dynamic select list in Drupal 7? Create a Field with dummy options via the UI and overriding the options with hook_form_FORM_ID_alter or Creating a dynamic select list from scratch via a custom module with the hook_form or different approach? Thanks 回答1: You could use Form API's #ajax (it used to be called #ahah in Drupal6) to do that. Here is an example for Drupal 7 (based on Examples for Developers) that shows two dropdowns where the first dropdown modifies

Drupal 7: Best Practice for a Dynamic Select List in Drupal 7

爱⌒轻易说出口 提交于 2019-12-02 17:44:42
What is the best practice for a dynamic select list in Drupal 7? Create a Field with dummy options via the UI and overriding the options with hook_form_FORM_ID_alter or Creating a dynamic select list from scratch via a custom module with the hook_form or different approach? Thanks You could use Form API's #ajax (it used to be called #ahah in Drupal6) to do that. Here is an example for Drupal 7 (based on Examples for Developers ) that shows two dropdowns where the first dropdown modifies the list of options of the second dropdown: Source of file mymodule.module : <?php /** * Implementation of

Style Option Elements in Select List (Add Padding and/or Margins)

天涯浪子 提交于 2019-12-02 05:23:18
问题 Is it possible to style the option elements of a select list/dropdown beyond background and font? I'm specifically looking to add some padding/margins so the list isn't as cramped. 回答1: Not possible if you want broad browser support. At least IE doesn't support it. There's then no other option than to mimic and progressively enhance the dropdown with <ul><li> and a good shot of JavaScript. You can get here some ideas what's possible with JS (jQuery actually) based dropdowns. 回答2: @Alex: we

Filtering a select list via input box & jquery

无人久伴 提交于 2019-12-02 02:51:23
问题 I was wondering if i could get some help with filtering a select list using an input box via jquery. Here's what my js looks like, but it doesnt seem to work. I'm guessing this is because options within a select list are not hide-able. <script type="text/javascript"> $(document).ready(function() { $("#inputFilter").change(function() { var filter = $(this).val(); $("#selectList option").each(function() { var match = $(this).text().search(new RegExp(filter, "i")); if (match > 0) { $(this).show(

Filtering a select list via input box & jquery

断了今生、忘了曾经 提交于 2019-12-02 02:18:19
I was wondering if i could get some help with filtering a select list using an input box via jquery. Here's what my js looks like, but it doesnt seem to work. I'm guessing this is because options within a select list are not hide-able. <script type="text/javascript"> $(document).ready(function() { $("#inputFilter").change(function() { var filter = $(this).val(); $("#selectList option").each(function() { var match = $(this).text().search(new RegExp(filter, "i")); if (match > 0) { $(this).show(); // Does not work } else $(this).hide(); }); }); }); </script> and here's my html <input id=

Style Option Elements in Select List (Add Padding and/or Margins)

偶尔善良 提交于 2019-12-01 23:50:13
Is it possible to style the option elements of a select list/dropdown beyond background and font? I'm specifically looking to add some padding/margins so the list isn't as cramped. Not possible if you want broad browser support. At least IE doesn't support it. There's then no other option than to mimic and progressively enhance the dropdown with <ul><li> and a good shot of JavaScript. You can get here some ideas what's possible with JS ( jQuery actually) based dropdowns. @Alex: we were in the same predicament as you seem to be. We too wanted to control the UI of the dropdown. Unfortunately as

Pass SelectList “SelectedValue” to Controller Action Method

人走茶凉 提交于 2019-12-01 10:57:21
I have a registration form which displays a users Name (textbox), Email (textbox) and Division (SelectList). The Name and Email are pre-populated (I'm using Windows Authentication, Intranet app), and I want to send the SelectedValue from the DropDown to my controller as an Int32, I don't want to send the entire SelectList back. This list is small now, but will grow to considerable size. I a class called RegistrationViewModel , it contains public properties for these fields. However, when I use SelectList for the DivisionList, I receive this error: No parameterless constructor defined for this