html.dropdownlistfor

ASP.NET MVC 3 - DropDownListFor Fails when URL Parameter Also Exists with Same Name as View Model Parameter

ⅰ亾dé卋堺 提交于 2020-01-14 14:15:14
问题 I am not sure if this is a bug with the DropDownListFor extension or what, but we had the following: http://mydomain.com/path/page?myparam=myvalue In my View Model I have the following: public string MyParam { get; set; } public List<SelectListItem> ParamOptions { get; set; } When I do the following in my View it fails to select the correct value: @Html.DropDownListFor(x => x.MyParam, Model.ParamOptions, "Select Value") However, when I change the parameter 'MyParam' in my view model to

How to get Dropdownlist selected value

送分小仙女□ 提交于 2020-01-07 01:30:07
问题 How to get dropdownList selected Item from CSHTML page. <div class="editor-field"> @Html.DropDownList("ROUTE_GROUP_ID", String.Empty) @Html.ValidationMessageFor(model => model.ROUTE_GROUP_ID) </div> 回答1: If you want its value in jquery you can do like this $('#ROUTE_GROUP_ID').val(); or if you want its value in controller you can access it from Request.Form["ROUTE_GROUP_ID"] or if your controller have a formcollection object then access the value like formcollectionobj["ROUTE_GROUP_ID"] 回答2:

Building a DropDownList in the Model?

偶尔善良 提交于 2020-01-06 15:07:49
问题 I have a service layer that exposes a method, which returns me a List, called GetStates. public List<StateObject> GetStates() My State Object is just a custom object I have created: public class StateObject { public int stateId { get; set; } public string description { get; set; } public Boolean isDefault { get; set; } } In my models, I am trying to create a model that will be used for my display and modification screen of a task. One thing this will be used for is handling the display and

Html.DropDownListFor does not bind boolean SelectList

泪湿孤枕 提交于 2020-01-05 08:09:32
问题 I have this code the constructs a select list as a boolean response var responseList = new List<SelectListItem>(); responseList.Add(new SelectListItem { Text = "Going", Value = bool.TrueString}); responseList.Add(new SelectListItem { Text = "Not Going", Value = bool.FalseString }); ViewData[ViewDataKeys.ResponseTo] = vatOptionList; In my view I use the dropdownlist helper below. @Html.DropDownListFor(m => m.ResponseTo, (IEnumerable<SelectListItem>)ViewData[ViewDataKeys.ResponseTo], "--Select-

HTML.DropDownListFor class assignment

心不动则不痛 提交于 2020-01-05 00:53:23
问题 Is it possible to assign my own class to the HTML.DropDownListFor() helper? 回答1: One of the overloaded method has an object htmlAttributes as last parameter in which you can specify extra attributes to be added to the generated html: Html.DropDownListFor(..., new { "class" = "myclassname" }; http://msdn.microsoft.com/library/ee703670.aspx 回答2: Didier's answer is mostly correct, but to define a class value in htmlAttributes object, you need to use this syntax: Html.DropDownListFor(..., new {

How can I return an empty list instead of a null list from a ListBoxFor selection box in Asp.net MVC?

浪子不回头ぞ 提交于 2020-01-04 06:44:47
问题 controller get action IList<InputVoltage> inputVoltagesList = unitOfWorkPds.InputVoltageRepository.GetAll.ToList(); pdsEditViewModel.InputVoltageList = inputVoltagesList.Select(m => new SelectListItem { Text = m.Name, Value = m.Id.ToString() }); ViewModel public IEnumerable<SelectListItem> InputVoltageList { get; set; } public List<int> SelectedInputVoltages { get; set; } View @Html.ListBoxFor(m => m.SelectedInputVoltages, Model.InputVoltageList) I want to receive a null list when a user

Using Html.dropdownList() in Javascript Code

≡放荡痞女 提交于 2020-01-03 04:29:10
问题 I want to add row to my table dynamicly like this : var tableRef = document.getElementById('tblData').getElementsByTagName('tbody')[0]; var newRow = tableRef.insertRow(tableRef.rows.length); var newCell = newRow.insertCell(0); newCell.appendChild(document.createElement('input')); var newCell = newRow.insertCell(1); newCell.appendChild('@Html.DropDownList("AppVersionGroupId", string.Empty)'); but output is : newCell.appendChild('<select id="AppVersionGroupId" name="AppVersionGroupId"><option

MVC (5) Populate a dropdown based on another [duplicate]

两盒软妹~` 提交于 2020-01-01 15:55:55
问题 This question already has answers here : better way to load 2 dropdown in mvc (5 answers) Closed 2 years ago . I know I can make a dropdown with a list of SelectedListItem> and @Html.DropDownList("someID") and os on.. My question is , what if you had 2 dropdowns, and the second dropdown depended on the selected item from the first dropdown? How do you populate it? With JS? How would you go about it? Would you change the populate with another list, change the whole dropdown or maybe have a

Disabled DropDownList razor mvc

主宰稳场 提交于 2019-12-30 18:33:26
问题 In my razor view, I use a drop down list. I want to have this control disabled (not selectable). My code is: <div class="field-list">@Html.DropDownListFor(model => model.LinguaCodiceMadre, Model.LinguaMadreList, new{ @disabled = "disabled" })</div> But it doesn't work, my control is always enabled. Html page code is: <select name="LinguaCodiceMadre" id="LinguaCodiceMadre" data-val-length-max="10" data-val-length="The field LinguaCodiceMadre must be a string with a maximum length of 10." data

Understanding how DropDownListFor is working in MVC3

强颜欢笑 提交于 2019-12-30 10:41:13
问题 I'm new to MVC3 and have been working on a small site using EF and 'Code First'. I'm trying to do a few things in a view dealing with a drop down list and am wondering what the best way to go about them is. I want a user to be able to select a rule from the dropdownlist, and depending upon which rule was selected, I would like a label on the page to show the rule name (without posting). I also need to be able to send the selected rule onto the next page. I haven't added all of the necessary