selectlist

Result of LINQ Query in MVC SelectList as Value and Text - not working

我是研究僧i 提交于 2019-12-22 05:29:11
问题 I am trying to use the result of a LINQ Query to populate a SelectList in a MVC 5 application. The LINQ query returns customer IDs. Model public partial class Pricelist { public int CustomerID { get; set; } public int SelectedCustomer { get; set; } public Pricelist(int customerID, int selectedCustomer) { } } View @Html.DropDownList("custList") Controller (1) var query = ((from s in db.Pricelists select s.CustId).Distinct()).ToList(); int i = 1; List<Pricelist> CustomerList = new List

Rails 3 and rspec - select from select list

心已入冬 提交于 2019-12-22 05:11:35
问题 I want to select value from select list in RSpec . For example i have such data: <div class="control-group"> <label class="control-label" for="user_teacher_leader_attributes_teacher_id">Teacher names</label> <div class="controls"> <select id="user_teacher_leader_attributes_teacher_id" name="user[teacher_leader_attributes][teacher_id]"> <option value="1" selected="selected">Math teacher</option> <option value="2">Physics teacher</option> </div> </div> I want to select option Physics teacher

Asp.net mvc select list

狂风中的少年 提交于 2019-12-21 20:34:00
问题 I need to create a select list, preserving the state, which is not part of the model passed to the view. I suppose I should be using a ViewBag to pass a List to the View ? Any advise on implementation and how to preserve the state of the select list (how do I pass the selected value back to action and to the view again (possible ways of doing this) ? The Action as of now: public ActionResult Images(string x, string y) { //some code ContentPage cp = this.ContentPage; return View(cp); } //Post

I Can't get a DropDownList to populate from table. EF and MVC4

你。 提交于 2019-12-18 09:58:48
问题 I believe this will create a list in my HomeController. But not sure what calls it or where it goes in the Controller beside maybe the first Add ActionResult (GET method). public static IEnumerable<SelectListItem> items() { using (oesacEntities_compact db = new oesacEntities_compact()) { var query = from s in db.tblSponsors select new { s.SponsorID, s.BizName }; return query.AsEnumerable() .Select(x => new SelectListItem { Value=x.SponsorID.ToString(), Text = x.BizName }).ToList(); } } I can

Best way to populate select list with JQuery / Json?

只愿长相守 提交于 2019-12-17 16:50:13
问题 Currently our dev team uses this pattern, but I can't help but wonder if there is a faster or more html-efficient way of accomplishing the same task. HTML <select id="myList" style="width: 400px;"> </select> <script id="myListTemplate" type="text/x-jQuery-tmpl"> <option value="${idField}">${name}</option> </script> And this is the Javascript: function bindList(url) { callAjax(url, null, false, function (json) { $('#myList').children().remove(); $('#myListTemplate').tmpl(json.d).appendTo('

Programmatically create select list

三世轮回 提交于 2019-12-17 06:34:10
问题 Does anyone know of a technique to programmatically create an HTML select list including options using JQuery? 回答1: 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)); }); 回答2: var s = $('<select/>'); var o = [1, 2, 3]; for (var i in o) { s.append($('<option/>').html(o[i])); } $('body').append(s); 回答3: I know this is old, but

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

邮差的信 提交于 2019-12-17 04:02:53
问题 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

How can I get this ASP.NET MVC SelectList to work?

扶醉桌前 提交于 2019-12-17 02:17:29
问题 I create a selectList in my controller, to display in the view. I'm trying to create it on the fly, sorta thing .. like this... myViewData.PageOptionsDropDown = new SelectList(new [] {"10", "15", "25", "50", "100", "1000"}, "15"); It compiles, but the output is bad... <select id="PageOptionsDropDown" name="PageOptionsDropDown"> <option>10</option> <option>15</option> <option>25</option> <option>50</option> <option>100</option> <option>1000</option> </select> Notice how no item is selected?

SelectList selected default value

一曲冷凌霜 提交于 2019-12-14 03:16:18
问题 I have this in my Controller: ViewBag.ClientID = new SelectList(db.Clients, "ID", "Name"); This in my View (using razor) @Html.DropDownList("ClientID", null, htmlAttributes: new { @class = "form-control",}) When I load my view I have the first client selected by default and I want to have "--Select Client--" 回答1: you can use this overload of Html.DropDownList() to add option label: @Html.DropDownList("ClientID", null, "Select Client", htmlAttributes: new { @class = "form-control"}) if you

Required data not displayed in html.dropdownlist MVC

五迷三道 提交于 2019-12-13 21:31:00
问题 I am trying to populate some data from model to view in a dropdown list. For that I have created my model as Model: public class NoOfSupportingLanguages { public int LanguageId { get; set; } public string LanguageName { get; set; } } public class OrganisationModel { public SelectList NoofSupportingLanguages { get; set; } } And on the controller side , something like this: Controller: public ActionResult Index() { List<NoOfSupportingLanguages> LanguageOption = new List<NoOfSupportingLanguages>