How to display selected value in dropdownlist in mvc


How to display selected value in dropdownlist in mvc. e. AllCards), "--Select--") Oct 31, 2017 · I want to display a dropdown list in Airline tab. cs, then click on the "Add" button. May 22, 2021 · In the following code of an ASP. Equals(Options. DropDownListFor(model => model. The following script is getting the value of the selected option and putting it in text box 1. Net will iterate through querystrings, form values and cookies. May 3, 2024 · 3. InputtedData, ddv) And I get 1 (the number one), the selectedvalue. In some cases, it may be necessary to get the selected text and value from a dropdown list in the controller action method. success: function (data) {. DropDownList("list",ViewData["list"] as SelectList) %>. Jan 31, 2014 · In fact, the DropDownList selected value returns the value of the ToString() method of Book . Jun 13, 2016 · I am using Visual Studio 2013 and creating MVC application and I have bind dropdownlist like this: var list = context. // with the value I will do something like this: User userinstance = new User {. So let's start. DropDownListFor(x => x. I want display default Active Feb 17, 2010 · Also, to anyone who has a SelectList with a different value attribute than the display text between the option tags for example: <option value="2">some text</option>. cshtml, it references this editor template and creates a dropdown with all the options in the enum. The dropdown names are (non-case sensitive): ReportName, Year, and Month. The dropdown is populated with values from the database. function up() {. Jun 11, 2012 · The thing is the DropDownList method searches the selected value based on the passed name in the Model, ViewData etc. So I have to put the Ids in my DropDownList, but I would like the list to display the title and the selected value to be the Id. Dec 27, 2009 · 1. How can I pass selected User to my controller method when I press the button? Oct 9, 2012 · In your example you have used productType for storing both the selected value and the list of available values. In this article, I will demonstrate the simple ways to populate a DropDownList using ViewBag, ViewData, TempData, jQuery, Model, Database, jQuery AJAX, and hardcoding in View. NET MVC you need 2 properties: Jan 31, 2018 · Step 1: Just right-click on the Controllers folder and add a New Scaffolded item. toString(); $("#hdn_dependent"). Oct 20, 2023 · We create a subject list that will be shown in a dropdown list. SET QUOTED_IDENTIFIER ON. Range(2000, 15). FindByValue(value). Feb 3, 2009 · This easy solution worked for my mvc5 project: in view: @{. Select the Select Movie Category (Simple) link. You will see how to use the Html. Jul 30, 2012 · 1. ViewBag. From the controller action, you're going to make the call the same way: <%= Html. id. DisplayFor(blah => blah. State, Model. var dep = $('#dependent'). only the Value will be submitted (which in your case was the ID). To get selected options for DropDownList you should write code in your action. This had me going for a while. val() to set value of select. the dropdownlist is populated from a database, and using Visual Studio, I connected to the DB and it created all the code file for the table. After reading at your question, it sounds like you want to have the drop down list supply a value for a lower section of the same page. Learn how to generate the dropdownlist HTML control using the HtmlHelper in a razor view. Feb 14, 2018 · The Selected Value of DropDownList is easily available using Model or using Request. In your view, use the DisplayFor method. You can also browse other related questions about ViewBag, dropdown lists, and ASP. Select "Class" and give a class name, like SubjectModel. I was able to create the table and display the values. Create a <SELECT> tag with one option and its value is "select". DropDownList(Model. So the idea is add a property in the ViewData with the dropdown's name and set the value to the one that you need to set in the dropdown and you are done! Dec 15, 2020 · I want to get the selected value 'YES' or 'NO' to do something in the controller like so: var theValue = dropdownList. HTML. Hope this helps. In order to render a DropDown in ASP. To achieve this, i am using ajax. Sep 22, 2010 · How to display selected value in the Dropdown list box. You can also compare different approaches and solutions from other related questions and answers. DropDownListFor(m => m. StateNames: For getting the values of the collection from the entity. ToString Jan 6, 2016 · Using the Select Tag helpers to render a SELECT element. Sep 23, 2015 · 2. getElementById("Ultra"). This is very simple but will result in an error if the dropdown May 22, 2014 · @Html. It looks to be actually trying to match the view model property with the display text and not the value attribute to choose the selected option. Dec 6, 2017 · STEP BY STEP SERVER SIDE BINDING DATA AND GETTING SELECTED VALUE OF DROPDOWNLIST CONTROL. – Dmitry Brazhkin. How to get selected value from dropdown list in mvc c#. Collection), don't use the foreach iterator. How to do cascading between two dropdownlists. “—Select--”: Default value, when the dropdown list will be populated. Text = x. ToString(), Selected = (value. USE [MBKTest] GO. The Text portion of the element is just for the user to see to make their selection's easier. NET MVC. As dropdown list selection will be changed, Form Post method will be called and that is second Action Employee() mentioned in above sample. ExecuteReader()) while (rdr. public class Student. StateDisplayModel> @Html. What are you trying to accomplish? Note HTML. GetName(type, value); imo what's happening is that its automatically setting the selected value of the drop down to match the model - using the enum name instead of its int value. role. Net world, you would do a PostBack on the "onselectedindexchange" and that would look at the item selected, then update the L/H/W fields with values from the "master widget entry" version. List < string > ListItems = new List < string > (); Dec 2, 2018 · Public Property SelectedBrandID As Integer. It’s surprising how many subtle, but frustrating traps one can fall into when building sites with ASP. But I want to display Yes, the selectedtext. NET Core 3. 0 and click Next. @Html. Jun 27, 2014 · I'm trying to reproduce the same code, by using Selected, but i cannot select a default value. Mar 9, 2009 · A workaround is to add a hidden field and htmlAttributes to the DropDownList: <input type="hidden" name="DealerTypes" id="DealerTypes" value="" /> <%= Html. Accounts, "AccountID", "AccountName")) edited May 1, 2017 at 18:03. Select Views ->stud_details and click on Finish button. Apr 6, 2011 at 12:39. Dec 31, 2009 · Set the SelectedValue to the value you want as the default DropDownList. Note also that the Id is of type string, because it is hashed. " -----Select List----- "will be the initial selected item of your dropdown with value equal to ''. NET MVC and show the selected value in the view, you can find a detailed answer with code examples in this Stack Overflow question. Now, in clasic ASP. NET MVC: There are 8 overloaded versions available for the DropDownList HTML Helper method, as shown in the below image. stateId, mcntry) @Html. Aug 29, 2012 · The branch and division properties must obviously be collections that will contain the selected values. //the value. SelectedValue = "value". NET MVC using Html. Selected = true; Alternatively you can use the FindByText method to search the DropDownList for an Item with Text matching the parameter. Sep 7, 2009 · If you want to learn how to set the selected value of a SelectList in MVC, you can find a helpful question and answer on Stack Overflow. In your action: var selectedValue = new List<int> {1, 2}; ViewBag. Jan 18, 2017 · When you use the DropDownListFor() (or DropDownList()) method to bind to a model property, its the value of the property that sets the selected option. DropDownList has like 9 overloads. Text would give 'German'. Id, new SelectList(Model. OrderBy(r =&gt; r. ModelItemsList, "ModelItemID", "ModelItemName"); } Just add a new item to the List<> you want to display in your view. Note that the MultiSelectList is used. Notice that we are passing a value of 1 for selectedValue parameter. The value for Select is clearly = true for one item but it's not shown as selected on the screen. When debugging I can see that Model. getElementById("mySelect"); Then, you can access to the mySelect options which is an array. name: The name of the form field to return. Make your dropdown like this: @Html. Create a ViewModel that has the selected value. Select(a=>new SelectListItem { Text = x, Value = x }) %>. DropDownListFor using model. GO. //Your code. ")] [Display(Name = "Employee District:")] public int? Jul 24, 2011 · 1. accountId, new SelectList(ViewBag. We will see later how dropdown list selected index changed call Post Action Dec 2, 2015 · When the form displays, the Drop-Down is shown but the form fields of L/H/W are empty/disabled until the user selects one from the DDL. Get DropDownList Selected Text and Value in Controller . EditorFor(model => model. Departments, "Id", "Name", "1"); Sep 7, 2016 · here in above example the 3rd parameter of DropDownListFor() i. and use jquery to fecth the selectted values in the multiselect dropdown. Again, the goal is to update each row with the values selected in the two dropdownlists in that row. document. public IActionResult Create() {. Net MVC. However it always displays instead of being hidden until called. Virtualization—The virtualization feature of the DropDownList allows you to display large datasets. Further, we will learn how this drop-down list will be displayed on view after collecting options from the controller and how the selected option can be further processed and render the selected value back to the user. Select(c => new SelectListItem { Value = c. SuperAdmin. The model class has a string called SelectedValue. However I can't find the right way to get this value from a partial view in my controller. SelectedItemId, Model. Oct 3, 2019 · I want to display the selected country name in dropdownlist while edit but I don't get my view properly View @model IEnumerable<Intrans. function run() {. – Carol Skelly. format("doSomething({0}); return false;", action) }) %>. NET MVC on the same site. DropDownList(ddl, ViewData["items"] as SelectList, new { onchange = string. 2. In a . I have a model class. Mar 17, 2022 · If you want to learn how to use ViewBag to create a DropDownList Html Helper in ASP. The drop-down list must be placed above the table. By default it is the property variable name that appears in the model class, unless overriden in the mark up. EndCurrentDeal) All well and good, but what I'm really looking to do is massage that into a dropdown like: <select>. Using the jQuery val () method. We will use the following Student model class and Gender enum. Ask Question Asked 13 years, 7 months ago. Now, our model is ready. ATX_Full)) }; Now when I call @Html. Selected = If(x. Id = id, True, False) })) And finally use DropDownListFor helper to show option lists: Related issue: MVC. mySelect. You could apply a CSS class to the dropdown: @Html. Shown below is sample: Model. Sep 16, 2014 · Here is a simple example of how to create a drop down list in ASP. ClearSelection(); dropdownlist. var dropdownlist = $("#Instrument"). Nov 17, 2017 · In Model i have made change from list<SelectList> to List<SelectListItem> after that i have PopulateCountry dropdownlist hardcoded data in controller which you can change it by replacing it with database. Name). In one of the view I add a dropdownlist and I bind this dropdownlist with my database like this. Jul 10, 2013 · Add another property to your model of the same type as the value parameter for your SelectListItems. zip file and select Extract All to unzip the file. So how do I display the selectedtext in a dropdownlist in a displaytemplate and not the selectedvalue? Per request: Mar 29, 2016 · In the above sample, first Action Employee() is to load all Employee List in the dropdown list and one default employee record. Select(rr =&gt; new SelectListItem { May 15, 2019 · The model bound to your view should have a property for the selected culture value. I have a collection of items I've pulled from the database. NET MVC5. Read()) list. hidden {. Templates—To control how the items, selected value, or a pop-up header are rendered, you can use the available templates. At Controller during POST mapLocationItemVal will have selected dropdown value. CategoryName input bound from the form to the backend via HTTP. answer> @Html. value"})%>. Create strongly typed view in EditorTemplates folder named like collection item class name. Jorge. select new SelectListItem. ToString(), Text = c. When using the DropDownList HTML Helper, developers can specify the data source for the dropdown list, the field to be displayed to the user, and the field that represents the value of Jul 17, 2013 · So the question seems very simple but not for me. <input type=submit value="Submit" />. Jan 27, 2017 · Then finally, use Razor on the view to display the Dropdown list like this. ValidationMessageFor(model => model. May 5, 2017 · from value in values. Use. I run my application default deactive value is display in dropdown list box. Add(new ModelItem{ }); SelectList modelItemSelectList = new SelectList(Model. Public Property BrandList As IEnumerable(Of SelectListItem) Then populate it inside controller action: . Parameters: htmlHelper: The HTML helper instance that this method extends. val(dep); Jul 6, 2009 · onkeyup="up()">. dropdownlist. <%= Html. agreed with Marwan. Sep 24, 2012 · and I get an actual dropdownlist. " We get an Add New Item Window. Step 1. Sep 4, 2013 · Add the SelectList to your model: build the class for that collection: public string Key { get; set; } public string Display { get; set; } and then in your controller, load the data for the MyListTable class from the database: using (SqlDataReader rdr = cmd. Syntax: selectedSelectElement. The textbox will populate with a value from the same table and the dropdown, based on the selected dropdown value. 1 MVC project, the Get action method Edit () is displaying a dropdown list of zipcodes. But you will vastly improve performance if you use ajax to just update the current page rather that regenerating the whole view again. Select(g => new SelectListItem { Value = g. MsgIntervals = msgInts; GetMsgIntervals method: public List<FormValues_MsgIntervals> GetMsgIntervals() {. Models { public class EmployeeReferral : Person { public int EmployeeReferralId { get; set; } //Company District //List [Required(ErrorMessage = "Required. Apr 6, 2014 · ViewData["list"]=list; return View(); you pass to the constructor: the IEnumerable object, the value field the text field and the selected value. Jun 11, 2012 · 26. Nov 14, 2017 · In MVC, when it comes to HTML elements where the user can select options to be submitted to the server (dropdownlist, listbox, etc). This is my partial view: @model List<aptest. DropDownListFor? I've been having a look online and have seen that it can be achieved by using the fourth parameter so like the below: @Html. Once you do that, put a Javascript function on your page that calls the method. The javascript to I use looks like this: $. Hidden("hdn_dependent") and we can get the values from the selected dropdown by creating an id to the dropdown. DropDownList("jobID", null, new {@id="job"}) and taskname text box : @Html. Apr 19, 2013 · You have to use Kendo UI DropDownList select method (documentation in here ). SelectedValue //this is pseudocode syntax but you understand I want to get. College_Names. Mar 21, 2014 · 1. DropDownList("dropdownlist", new SelectList(Model, "text", "text")) <button type="submit">next</button> May 15, 2012 · 4. May 7, 2015 · One of the DropsDownList's are populated when the page is created and the second will be populated based on the option that the user chooses in the first DropDownList. for now, all I am trying to achieve is to add the poulated dropdownlist for Departments to the form. public int Selected {get;set;} public IEnumerable<Option> Options {get;set;} step 3. In this Stack Overflow post, you can find a detailed answer with code examples and explanations. You can use the FindByValue method to search the DropDownList for an Item with a Value matching the parameter. Text = value. DropDownList ("DealerTypesDD", ViewData ["DealerTypes"] as SelectList, new { @onchange = "DealerTypes. selectedIndex will give you the current selected index of the tag. jQuery is a JavaScript library whose val () method can be used to get the value of the selected dropdown item. In your GET action, create an object of your view model, load the EmployeeList collection property and send that to the view. val(); Example: The below code explains the use of the jQuery val () method to get the value of the selected item. ajax({. Jul 1, 2021 · This article will demonstrate how to bind the values to Razor DropDownList in various ways using ASP. ProjectSuppliers= new MultiSelectList(SupplierList, "Id", "SupplierName", selectedValue ); . DropDownListFor () Helper Method. well the logical option is that the param from the HTML form would be this Category. The above shown code is best and simplest way to bind Dropdownlist in MVC. Example from MVC 4 for dropdownlist validation on Submit using Dataannotation and ViewBag (less line of code) Models: namespace Project. <option value="true" selected="selected">Yes</option>. value = this. Oct 15, 2015 · 1. Roles, "Id", "Name"), htmlAttributes: new { @class = "form-control"}) But still not working, I did not got the selected value. answered May 16, 2013 at 19:02. The HtmlHelper class includes two extension methods to generate the <select> control in a razor view: DropDownListFor() and DropDownList(). Here, create a new connection and click on Next option. Form collection, but in order to get the Selected Text, the Selected Text is copied to a Hidden Field using jQuery and then it is fetched inside Controller in ASP. Open the StartMusicStore. Id, . For example: you drop down may have an itme like. Name }); Sep 21, 2015 · @Html. DropDownList("MeasurementType", "Select")%> does exactly what it should. In short, how would you set a particular year as a Selected Value in this list: ViewBag. Aug 4, 2022 · How to set multiple selected value and show them in dropdownlist with MVC? I suggest that you use the MultiSelectList. Step 2: Select MVC Controller- Empty. In that ViewModel have the list of items you want in the select list. Roles. Items. NET MVC confuse me. Here I have a form with 3 dropdowns that posts to an ActionResult. taskName, new {@id="taskname"}) do like this, write jquery event for dropdown index change event, and send ajax call to get Task Name against the job Id selected from the dropdown list: $('select#job Jun 18, 2010 · Try not using the int value for the enum / instead of: item. I currently have scaffolded a view where a boolean property of my model gets passed to the Html. GetMsgIntervals(); And passed to the view using ViewBag: ViewBag. 0. ToList() . EditorFor helper: @Html. There is a loop that generates each row in the table. In my case, I added a empty "ModelItem" to my List<ModelItem Nov 19, 2021 · There are dozens of dynamically generated rows in total, which results in twice as many dropdownlists with values to track. And a full example of the proper way to build a multiple select dropdown using a view model: public int[] SelectedValues { get; set; } public IEnumerable<SelectListItem> Values { get; set; } Nov 29, 2018 · I need the view to create a SELECT with those 4 options, and option 2 and 4 to be initially selected. EditorFor (x => x. ModelItemsList. Jun 26, 2020 · I am using ASP. var mySelect = document. Dec 23, 2008 · What I don't like about EnumDropDownListFor() is that it saves into the DB the int value of the enum, not the text, so if you ever choose to add a new enum item, it must necessarily go at the end of the list, so as not to loose the relationship of the saved database int values to original positions of the enum items. NET MVC framework. – Apr 17, 2013 · public Member selected { get; set; } Updated Dropdown list control: This will return the selected value from the dropdown list into the property selectedValue. So, in this case SelectedValue would be de and SelectedItem. Right-click on the Model folder in Solution Explorer, then click on "Add New Item. Text gives you the display text. Value = Enum. StateNames: Collections of states. EmployeesList = new List<Employee>. Feb 22, 2021 · Learn how to get the selected value of a dropdown list in ASP. val(1); Jan 7, 2021 · Select -> "The Generate from database" option and click Next. Each item of the collection has an ID and a Name value. The controller action corresponding to the view, should assign this a value to this property. You can also browse other related questions and answers about MVC, ViewData, DropDownList and SelectListItem. Compare with other related questions on MVC dropdownlists and find the best way to populate and display them. DropDownList () HTML Helper Method in ASP. NET in VB - Select List to Html Mar 16, 2013 · Drop down lists in ASP. Aug 13, 2015 · When you submit, the value of choice will be the value of the selected option so you can filter the data and return the view. cshtml file like so: Mar 5, 2015 · When "Other" is selected from the DDL all I want is for the textbox to appear. Example: Student Model. POST value at the moment im using nancy server and owin a lot more which work with posted values bounded via ajax to C# backend (to keep it as stricly typed as possible), but this would be the logical outcome. Value = x. . As long as you include your dropdown names, the selected values will be preserved. Declare the mySelect variable which contains the <select> DOM. DropDownList If your View it's strongly typed to some Model you may change your code using a helper to created a strongly typed dropdownlist, something like. See the code examples, explanations and solutions provided by the community. data("kendoDropDownList"); If you know the index you can use: // selects by index. Value = value. val(). Departments = new SelectList(db. Core. You have to have a submit button, or a similar construct, in order Apr 25, 2015 · You need to set value in the success callback method of $. The reason that your List of members is returned null is because HTML does not return the options in a drop down list, it only returns the selected value. [tblCities] Script Date: 30-Nov-17,Thu 6:34:14 PM ******/ SET ANSI_NULLS ON. Feb 24, 2016 · I am currently new to Asp. Then, choose Entity Framework 5. NET Core MVC is a server-side helper method that dynamically generates a dropdown list (HTML <select> element) on a web page. select(1); Mar 28, 2014 · I know there are multiple threads on how to get the selected value of a DropDownList. fn. ajax(), as it is asynchronous and also you can use $. How to display values based on dropdown selection in MVC? This is a common question for many developers who use ASP. Oct 28, 2009 · Learn how to make a HTML dropdownlist disabled or readonly with different methods and scenarios on Stack Overflow. The following code snippet may help you. Mar 18, 2013 · 28. [HttpGet] public ActionResult Create() {. in the View: <%=Html. the code you posted <%= Html. Model. On the view set this model value to the drop down list Jul 5, 2023 · MVC pattern focuses on segregating the code in model, view and controller format. To make a dropdown list you need two properties: a property to which you will bind to (usually a scalar property of type integer or string) a list of items containing two properties (one for the values and one for the text) In your case you only have a list of string which cannot be exploited to create a usable drop down list. Creating forms for the web is one of them. Jan 1, 2019 · I want to only display the albums from the selected category, or all albums from all categories, using Ajax and jQuery. ToString(), Value = value. Jan 5, 2015 · I am very new to MVC and I am trying to make a CreateEmployee form in MVC. Mar 24, 2016 · x=>x. step 2. stateId, "", new { @class = "text-danger" }) Jun 26, 2013 · Each time the user selects a value in one of these dropdownlist do I want the value to be saved to the backend (database). net MVC . Sizes. Add(new MyListTable. Id contains the selected value. NET MVC application, dropdown lists are commonly used to allow users to select options from a list. ToString(); use: item. Jun 24, 2023 · Right click the DDL_Starter. Step 3: Enter the controller name as SampleController and modify the Index () with the code below: public ActionResult Index () {. new {@id=”ddlState”}: In this part we can define an id, class and name for the control. step 1. display: none; } This hidden class could of course be applied dynamically based on some property value of the view model. SelectedCard, new SelectList(Model. Then by using mySelect, you can get the attributes of the <select> tag. Internally, the methods generate their own IEnumerable<SelectListItem> and set the Selected property based on the value of the property, and therefore setting the Selected property in your code How can I set the selected value of a Html. It seems that by default, the dropdown displays the first zipcode in the list (i. url: 'getCities/Trips', type: 'post', data: {. $("#ddlChannel"). YearsList = Enumerable. It’s common to spend hours on something trivial, such as displaying a selected value in a DropDownList on postback, or getting that selected value in a controller. getElementById("srt"). Mar 6, 2013 · More detail please. Status, new List<SelectListItem> { new SelectListItem{Text="Active", Value="True"}, new SelectListItem{Text="Deactive", Value="False"}}) In view I am using this drop dowenlist coding. The DropDownList HTML Helper in ASP. Apr 21, 2014 · 1. value; The following script is getting a value from a text box 2 and alerting with its value. You can alternatively use ViewBag if you do not want to add a property to your Model. As Sep 23, 2016 · A solution for either a select tag helper or a DropdownList html helper will be fine - but Selected value has to set from action method. 1 MVC to create a page with a form. Personally, I would have strongly-typed views Apr 10, 2019 · // HERE TODO // HOW do I make an auto select value in Dropdowlist --// When page loads, the dropdownlist will load the auto-select value base on the value displayed by Texboxfor // sample: sugar; because this value is base on the value in texboxfor = Code // Load listC in viewbag public void ListCDropDownList() { var itemsQuery = from k in db Sep 18, 2023 · Above you can see that the values required are returned from the database by calling a method: List<FormValues_MsgIntervals> msgInts = _UserSettingsFunctions. SelectedValue property gives you the actual value of the item in selection whereas SelectedItem. For collections use @Html. Create tblCities table for Dropdownlist datas, SQL Script. Create a SelectList object and pass that to your View. You can do it like this all inlined in your *. To have the IT department selected, when the departments are loaded from tblDepartment table, use the following overloaded constructor of SelectList class. For example, if it's an int, do this: public int SelectedCard { get; set; } Then, change your DropDownListFor like so: @Html. States, "--Select a State--") The 1st parameter is the property of the model to update, the 2nd is the list of data, and 3rd is the default message that will be displayed. options[] mySelect. The form has a dropdown and a textbox. value = document. sln file with Visual Web Developer 2010 Express ("Visual Web Developer" or "VWD" for short) or Visual Studio 2010. Aug 8, 2011 · When the ActionResult is posted to, ASP. <asp:ListItem Text="German" Value="de"></asp:ListItem>. Models. EditorForModel() in my Ball. Basically you should: // get a reference to the dropdown list. public class MultiCategoryViewModel { public int[] Category { get; set; } public MultiSelectList Categories { get; set; } } Jun 3, 2015 · create an hidden element. (Answer edited to include the insert record operation). Here, check the college table and in View, we have checked our View with the name schoolname. DropDownListFor helper method and the SelectList constructor to create a dropdown list with a predefined value. Press CTRL+F5 to run the application and click the Test link. I've tried this piece of code: @Html. There is you can use normal syntax for DropDownListFor method. var vm = new MyViewModel(); vm. /****** Object: Table [dbo]. Here is a working example: Model Class: public int EmployeeId { get; set; } public string Name { get; set; } public string Department { get; set; } View: Grouping—You can bind the DropDownList to grouped data sources. ToString(), Text = g. NET core MVC using different methods and examples. I don't want to page to reload so I guess the best way to achive this is with ajax, and this is what I need help with. DropDownList("DropID", Range(0, 10). Items, new { @class = "hidden" }) and then define the hidden CSS class: . IEnumerable<SelectListItem> items = db. DropDownList is not strongly typed. BrandName, . 1301) as the selected value. For that I am using Viewbag in controller to load the data in dropdown list. What I am doing wrong? Learn how to create a dropdownlist in MVC 4 with Razor using C# from this Stack Overflow question. Controller CollegeController. This string represents that previously selected value. ch rm ck pj sj hx ej uq rg fm