selectlist

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

SelectList pulling info from ViewBag: not creating value=“…” in generated html

你。 提交于 2019-12-11 09:48:26
问题 I'm trying to create a client-side validated dropdown list in an MVC4 application using the Razor view engine. The code in the view to generate the dropdown list is as follows: @Html.DropDownList("Test", new SelectList(ViewBag.AvailableLoBsDescriptions, ViewBag.AvailableLoBsIds), "--none--") Note that ViewBag.AvailableLoBsDescriptions is created in the controller using an IList while ViewBag.AvailableLoBsIds is also created in the controller using an IList. What I expected to happen is have

LINQ Union with Constant Values

冷暖自知 提交于 2019-12-11 09:07:35
问题 Very primitive question but I am stuck (I guess being newbie). I have a function which is supposed to send me the list of companies : ALSO, I want the caller to be able to specify a top element for the drop-down list as well.. (say for "None"). I have following piece of code, how I will append the Top Element with the returning SelectList? public static SelectList GetCompanies( bool onlyApproved, FCCIEntityDataContext entityDataContext, SelectListItem TopElement ) { var cs = from c in

Model binding form to a List using dropdown. binding failing 1 way for dropdown

核能气质少年 提交于 2019-12-11 06:33:24
问题 I have an action called Sessies. In this action i am creating 'Sessies' objects from a form. if they don't exist i add them in the DB, if there are already Sessies objects connected to the 'Reeksen' object, i load the 'Sessies' into the form so that they can be edited. so i have a create and edit in 1 and the same form. Also, a 'Reeksen' has a predefined number of 'Sessies' which can not be changed. so i let the user make all 'Sessies' in one time (cos the amount of sessies will be from 1 to

set select list to current date using Jquery

杀马特。学长 韩版系。学妹 提交于 2019-12-11 03:34:44
问题 I am using Jquery mobile, and I have these two select lists, I want to set the selected options for the to lists to the current day and month .. edit I am using JqueryMobile the code for 2 lists : <fieldset data-role="controlgroup"> <legend>تاريخ اخر دورة شهرية : </legend> <label for="select-choice-day">أختر الشهر</label> <select name="select-choice-day" id="select-choice-day"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option>

Setting default selected value of selectlist inside an editor template

╄→гoц情女王★ 提交于 2019-12-10 17:46:20
问题 I have this code to set the default value of my select list: public ActionResult Register() { IList<Country> countryList = _countryRepository.GetAllCountry(); var registerViewModel = new RegisterViewModel { CountryId = 52, CountryList = new SelectList(countryList, "CountryId", "CountryName", "Select Country") }; return View(registerViewModel); } I have this on my view and this works well sets the selected country value to 52: <%: Html.DropDownListFor(model => model.CountryId, Model

How can I restore the order of an (incomplete) select list to its original order?

随声附和 提交于 2019-12-10 17:08:16
问题 I have two Select lists, between which you can move selected options. You can also move options up and down in the right list. When I move options back over to the left list, I would like them to retain their original position in the list order, even if the list is missing some original options. This is solely for the purpose of making the list more convenient for the user. I am currently defining an array with the original Select list onload. What would be the best way to implement this? 回答1

Displaying data in a SelectList in ASP.NET Core

匆匆过客 提交于 2019-12-10 13:09:58
问题 I've tried a few different approaches. I'm not sure why but my SelectList/DropDown is empty. It shows no data. I'm not sure where I am going wrong. I have an ASP.NET Core App. Entity Framework Core. Db First. I am using a repository pattern. Here is my Model Class public partial class Commodity { public Guid Oid { get; set; } public string Code { get; set; } } This is my Interface: interface ICommodityRepository { IEnumerable<Commodity> GetAll(); } My Repository: public class

Modelbinding with SelectList

筅森魡賤 提交于 2019-12-10 11:37:28
问题 I create a DropDown with the Html.DropDownList(string NameSelectListInViewData) method. This generates a valid Select input with the correct values. And all is well. Upon submit however, the value in the source SelectList is not bound. Case: ViewData.SearchBag.FamilyCodes: public SelectList FamilyCodes { get; set; } Html that generates the dropdown: <%=Html.DropDownList("SearchBag.FamilyCodes")%> Generated html: <select id="SearchBag.FamilyCodes" name="SearchBag.FamilyCodes"> <option value="

MVC DropDownList selected value not working

牧云@^-^@ 提交于 2019-12-10 03:24:13
问题 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