html.dropdownlistfor

MVC4 binding drop down list in a list (bug)

拟墨画扇 提交于 2019-12-06 05:37:06
问题 I have the below code in a view. (index.cshtml) Binding Problem The first drop down selects the correct value, based on the 'ChildItem' editor template. The second example using an inline drop down list does not work I don't want to create an editor template just to display drop down values. The odd thing is that TextBoxFor will show the correct value. This seems to be an issue just with the drop down list. How do I fix the binding so that the second drop down works? I debugged it. It would

insert values from a drop down list to database table

元气小坏坏 提交于 2019-12-05 05:41:28
问题 I am new to PHP. When i am trying to insert the value from drop down list to database table showing some errors the code <html> <head> <title>OPTION</title> </head> <body> <form action="option.php" method="get"> Name :<select name="name"> <option value="name1">name1</option> <option value="name2">name2</option> <option value="name3">name3</option> <option value="name4">name4</option> </select><br> <input type="submit" name="submit" value="Insert"> </form> </body> </html> <?php if(isset($_GET[

MVC DropDownList selected value not working

人盡茶涼 提交于 2019-12-05 03:06:06
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 is Not selected . How to Fix this problem? Update The culprit was ViewBag.Title matching my model.Title.

Html.DropDownListFor not behaving as expected ASP.net MVC

亡梦爱人 提交于 2019-12-04 16:58:41
I am new to ASP.net MVC and I am having trouble getting dropdown lists to work correctly. I have a strongly typed view that is attempting to use a Html.DropDownListFor as follows: <%=Html.DropDownListFor(Function(model) model.Arrdep, Model.ArrdepOptions)%> I am populating the list with a property in my model as follows: Public ReadOnly Property ArrdepOptions() As List(Of SelectListItem) Get Dim list As New List(Of SelectListItem) Dim arriveListItem As New SelectListItem() Dim departListItem As New SelectListItem() arriveListItem.Text = "Arrive At" arriveListItem.Value = ArriveDepart.Arrive

insert values from a drop down list to database table

依然范特西╮ 提交于 2019-12-03 20:27:58
I am new to PHP. When i am trying to insert the value from drop down list to database table showing some errors the code <html> <head> <title>OPTION</title> </head> <body> <form action="option.php" method="get"> Name :<select name="name"> <option value="name1">name1</option> <option value="name2">name2</option> <option value="name3">name3</option> <option value="name4">name4</option> </select><br> <input type="submit" name="submit" value="Insert"> </form> </body> </html> <?php if(isset($_GET['submit'])) { $name=$_GET['name']; $c=mysql_connect("localhost","root",""); mysql_select_db("test");

mvc c# html.dropdownlist and viewbag

徘徊边缘 提交于 2019-12-03 17:50:12
问题 So I have the following (pseudo code): string selectedvalud = "C"; List<SelectListItem> list= new List<SelectListItem>(); foreach(var item in mymodelinstance.Codes){ list.Add(new SelectListItem { Text = item.Name, Value = item.Id.Tostring(), Selected = item.Id.ToString() == selectedvalue ? true : false }); } ViewBag.ListOfCodes = list; on my view: <%: Html.DropDownList("Codes", (List<SelectListItem>)ViewBag.ListOfCodes , new { style = "max-width: 600px;" })%> now, before it reaches the view,

In Yii framework how can I Combine columns and show as display string in dropdownlist

假如想象 提交于 2019-12-03 12:38:19
问题 I have a dropDownList in my view, it is populating from clients table, the table contains columns like first_name , last_name , id etc., Now I want to show the first_name and last_name as display text and id as value in drop down list, I'm done with id as value and first_name as display text, but here I want to combine those columns ( first_name and last_name ) and use as display text. in model function getClients() { $Clients = Client::model()->findAll(); $list = CHtml::listData($Clients ,

MVC5 view drop down list

天大地大妈咪最大 提交于 2019-12-03 09:03:19
In a C# MVC5 Internet application view, how can I display a dropdown list for a user to select a list item that is populated from a View Model list? Here is the ViewModel code: public class MapLocationItemViewModel { [Editable(false)] public int mapLocationForeignKeyId { get; set; } public List<string> mapLocationItemTypes { get; set; } public MapLocationItem mapLocationItem { get; set; } } Here is the code that I currently have in the View : <div class="form-group"> @Html.LabelFor(model => model.mapLocationItem.mapLocationItemType, new { @class = "control-label col-md-2" }) <div class="col-md

MVC DropDownList OnChange to update other form fields

拈花ヽ惹草 提交于 2019-12-03 08:11:07
问题 I am new to MVC (I am moving over from the dark side of traditional ASP.Net) and I know that SO is more of a "why doesn't this work" but, being new to MVC, I just wanted to ask how something is achieved - I don't really have any code or markup because I don't know how at the moment. Right, using an analogous example... I have a form that has a drop-down of a list of "Widgets" (have that working, thanks to SO) ... and then there are other fields (Length/Height/Width) which have "default"

DropDownListFor with a custom attribute with - in attribute name?

为君一笑 提交于 2019-12-03 06:32:34
问题 Question: I need to create a dropdownlist like this: <select id="ddCustomers" data-placeholder="Choose a customer" class="chzn-select" style="width:350px;" tabindex="1" multiple> Now I can add custom attributes like this: @Html.DropDownListFor(m => m.Id, Model.Values, new { @disabled = "disabled" }) Unfortunately, if there is a "-" in the variable name, then it doesn't compile. @Html.DropDownListFor(m => m.Id, Model.Values, new { @disabled = "disabled", @data-placeholder = "whatever" }) And