selectlist

DropDownListFor, selected = true doesn't work

不羁的心 提交于 2019-12-01 10:23:31
问题 Select doesn't work for me with DropDownListFor. Can anyone help me? I have musiccategories and artists that belong to one musiccategory. On my page I want to show artist details, and I want the dropdownlist to load all musiccategories with the specified artists music category selected. But I can't make one specified option in the drop down list selected, the first option is always selected at first. My controller: public ActionResult Index() { ClassLibrary.Artist a = GetArtist(); System

Pass SelectList “SelectedValue” to Controller Action Method

有些话、适合烂在心里 提交于 2019-12-01 08:25:46
问题 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

Selected value in asp.net MVC 4.0 dropdownlist

谁说胖子不能爱 提交于 2019-11-30 06:00:00
问题 I am trying to make a dropdown list using DropdownListFor function and I want to have a value selected in it. I have searched a lot and found the similar kind of solution of having a SelectList object in the ViewModel , I tried it something like this In my ViewModel I used a property of type SelectList like this SelectList HoursToSelect = new SelectList(MyDictionaryObject, "Value", "Key", 14/*selected value*/); and I was using it like this @Html.DropDownListFor(m => m.EndsOnHour,

Angularjs checkbox checked by default on load and disables Select list when checked

拥有回忆 提交于 2019-11-29 22:48:59
noob on stack overflow here. I am working on a webpage that has a transfer job function. This lets the user check a check-box to send the job back to the office, or select a technician from a list of all that are available. My question is how to setup the check-box so that it is checked by default when the page loads and have the select list disabled accordingly. Here is the code that I have for it at the moment: <div ng-app=""> Send to Office: <input type="checkbox" ng-model="checked" ng-checked="true"><br/> <select id="transferTo" ng-disabled="checked"> <option>Tech1</option> <option>Tech2<

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

大憨熊 提交于 2019-11-29 18:21:58
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't seem to send it to the Add view or to reference it from the Add view: <div class="editor=field">

Selected value in asp.net MVC 4.0 dropdownlist

て烟熏妆下的殇ゞ 提交于 2019-11-28 12:39:56
I am trying to make a dropdown list using DropdownListFor function and I want to have a value selected in it. I have searched a lot and found the similar kind of solution of having a SelectList object in the ViewModel , I tried it something like this In my ViewModel I used a property of type SelectList like this SelectList HoursToSelect = new SelectList(MyDictionaryObject, "Value", "Key", 14/*selected value*/); and I was using it like this @Html.DropDownListFor(m => m.EndsOnHour, HoursToSelect) This all was working fine and fulfilled my requirement completely But the problem is due to my

Problem with ASP.Net MVC SelectLIst and List<SelectListItems>

谁说我不能喝 提交于 2019-11-28 06:21:12
I'm extending an Enum and, given the following code, selectListItems is a generic List of SelectListItems that has all the correct values for my Enum. The first foreach loop works fine. However, when I create the actual SelectList and pass in selectListItems , all the values are lost. How can I keep those values intact? foreach (SelectListItem item in selectListItems) { string tex = item.Text; string val = item.Value; string sel = item.Selected.ToString(); } SelectList selectList = new SelectList(selectListItems); foreach (SelectListItem slid in selectList) { string tex = slid.Text; string val

Best way to populate select list with JQuery / Json?

余生颓废 提交于 2019-11-28 01:23:59
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('#myList'); }); } This is a function I wrote to do just that. I'm not sure if it's faster than jQuery

Set selected value in SelectList after instantiation

拜拜、爱过 提交于 2019-11-27 21:04:38
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? awrigley 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 initialize the SelectList (s) when you need to. An immediate benefit of this practice is that it allows you

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

╄→尐↘猪︶ㄣ 提交于 2019-11-27 19:20:50
(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 .First().Properties.First().PropertyGroups select new { g.eFinGroup.Key, Value = g.eFinGroup.Description }