selectlist

How to have a drop down <select> field in a rails form?

吃可爱长大的小学妹 提交于 2019-11-27 10:29:07
I am creating a scaffold - rails g scaffold Contact email:string email_provider:string but I want the email provider to be a drop down (with gmail/yahoo/msn as options) and not a text field. How can I do this ? You can take a look at the Rails documentation . Anyways , in your form : <%= f.collection_select :provider_id, Provider.order(:name),:id,:name, include_blank: true %> As you can guess , you should predefine email-providers in another model - Provider , to have where to select them from . Or for custom options <%= f.select :desired_attribute, ['option1', 'option2']%> You create the

How can I add an item to a SelectList in ASP.net MVC

微笑、不失礼 提交于 2019-11-27 06:42:37
Basically I am looking to insert an item at the beginning of a SelectList with the default value of 0 and the Text Value of " -- Select One --" Something like SelectList list = new SelectList(repository.func.ToList()); ListItem li = new ListItem(value, value); list.items.add(li); Can this be done? There really isn't a need to do this unless you insist on the value of 0. The HtmlHelper DropDownList extension allows you to set an option label that shows up as the initial value in the select with a null value. Simply use one of the DropDownList signatures that has the option label. <%= Html

How can I combine two fields in a SelectList text description?

こ雲淡風輕ζ 提交于 2019-11-27 01:12:05
I want put in a selected list labels the name and surname of people of an EF model. I've tried with this: public ActionResult Insert() { ViewData["accountlist"] = new SelectList(time.Anagrafica_Dipendente.ToList(), "ID_Dipendente", "Surname Name", null); Giustificativi g = new Giustificativi(); return View(g); } but VS returns an error, because there isn't a attribute called "surname name". how can i concat the name and surname in the selectlist label? thanks you could do something like this: ViewData["accountlist"] = new SelectList((from s in time.Anagrafica_Dipendente.ToList() select new {

Programmatically create select list

£可爱£侵袭症+ 提交于 2019-11-27 00:51:32
Does anyone know of a technique to programmatically create an HTML select list including options using JQuery? var arr = [ {val : 1, text: 'One'}, {val : 2, text: 'Two'}, {val : 3, text: 'Three'} ]; var sel = $('<select>').appendTo('body'); $(arr).each(function() { sel.append($("<option>").attr('value',this.val).text(this.text)); }); var s = $('<select/>'); var o = [1, 2, 3]; for (var i in o) { s.append($('<option/>').html(o[i])); } $('body').append(s); I know this is old, but what the hey: $selectBox.html($.map(myArray, function(){ return $('<option/>', {text: this}); })); This is very

Set selected value in SelectList after instantiation

别等时光非礼了梦想. 提交于 2019-11-26 20:32:21
问题 Am I right to think that there is no way to set the selected value in the C# class SelectList after it is created? Isn't that a bit silly? 回答1: I think you are fighting the framework. The data going into your views should be created at the Last Possible Minute (LPM). Thinking this way, a SelectList is a type to feed the DropDownList HTML helper. It is NOT a place to store data while you decide how to process it. A better solution would be to retrieve your data into a List<T> and then

How do you properly create a MultiSelect <select> using the DropdownList helper?

南笙酒味 提交于 2019-11-26 19:50:29
问题 (sorry, there are several item here but none seems to allow me to get this working.) I want to create a DropDownList which allows multiple selection. I am able to populate the list but I can't get the currently selected values to seem to work. I have the following in my controller: ViewBag.PropertyGroups = from g in db.eFinGroups where g.GroupType.Contents == "P" select new { Key = g.Key, Value = g.Description, Selected = true }; ViewBag.SelectedPropertyGroups = from g in company.Entities

There is no ViewData item of type 'IEnumerable<SelectListItem>' that has the key 'xxx'

本小妞迷上赌 提交于 2019-11-26 17:46:22
There are a couple of posts about this on Stack Overflow but none with an answer that seem to fix the problem in my current situation. I have a page with a table in it, each row has a number of text fields and a dropdown. All the dropdowns need to use the same SelectList data so I have set it up as follows: Controller ViewData["Submarkets"] = new SelectList(submarketRep.AllOrdered(), "id", "name"); View <%= Html.DropDownList("submarket_0", (SelectList)ViewData["Submarkets"], "(none)") %> I have used exactly this setup in many places, but for some reason in this particular view I get the error:

How to have a drop down <select> field in a rails form?

霸气de小男生 提交于 2019-11-26 15:12:11
问题 I am creating a scaffold - rails g scaffold Contact email:string email_provider:string but I want the email provider to be a drop down (with gmail/yahoo/msn as options) and not a text field. How can I do this ? 回答1: You can take a look at the Rails documentation . Anyways , in your form : <%= f.collection_select :provider_id, Provider.order(:name),:id,:name, include_blank: true %> As you can guess , you should predefine email-providers in another model - Provider , to have where to select

How to set default value to select list in MVC during run time

自作多情 提交于 2019-11-26 14:49:25
问题 I have view in which it loop through the model and display the details in editable mode. One of the model value is from a select list like below @if (Model != null) { for (int i = 0; i < Model.provider_service_dtls.Count; i++) { <tr> <td> @Html.DropDownListFor(m => m.provider_service_dtls[i].activity_code_type, (SelectList)@ViewBag.activity_code_type, "--- Select Activity Code Type ---", new { @class = "m-wrap" })</td> <td>@Html.TextBoxFor(m => m.provider_service_dtls[i].activity_name)</td> <

What is the best ways to bind @Html.DropDownListFor in ASP.NET MVC5?

核能气质少年 提交于 2019-11-26 14:48:43
问题 I want to bind @Html.DropDownListFor from Model data without using Viewbag and look at many different examples on the web. But most of them use Viewbag or an extension method and I want a better approach to solve this problem. I tried the the following methods but it does not seem to work: @Html.DropDownListFor(m => m.LabId, new SelectList(Model.Lab, "Id", "Name"), "---- Select----", new { @class = "selectpicker" } ) Is it possible to bind @Html.DropDownListFor directly from Model without