Here is my code :
@Html.DropDownListFor(model => model.Category, new List {new SelectListItem { Text = "Select", Value= "0"},
new SelectListItem { Text = "Creator", Value= "C"},new SelectListItem { Text = "Assignee", Value= "A"},
new SelectListItem { Text = "Reporter", Value= "R"} })

Rajeev PunhaniPosted Jul 9, 2016, 1:46 AM
If the above solution is helpful then,accept the answer.
Rohit ManePosted Mar 28, 2016, 10:26 AM
You may not get this easily with the default model binding. You have to a small workaround like this.
1) Add a new property to your model/viewmodel to store the selected text
2) Use
Html.HiddenForHelper method to create a hidden variable in the form for this property3) Use little javascript to override the submit ! ie; When user submits the form, Get the selected Text from the dropdown and set that value as the value of the Hidden field.
Now in your
HTTPPostaction method, This will be available in theSelectedTypeproperty.Vishwakant TripathiPosted Mar 28, 2016, 5:09 AM
EmpTest
All the best.
vandana rathiPosted Mar 25, 2016, 8:41 AM
Vishwakant TripathiPosted Mar 23, 2016, 6:18 AM
1.) http://stackoverflow.com/questions/20225823/jquery-ajax-callback-onchange-from-dropdownlist
2.) https://api.jquery.com/change/
vandana rathiPosted Mar 23, 2016, 3:32 AM
Vincent Maverick DuranoPosted Apr 29, 2015, 8:44 AM
http://geekswithblogs.net/dotNETvinz/archive/2011/06/03/asp.net-mvc-3-creating-a-simple-sign-up-form.aspx
http://geekswithblogs.net/dotNETvinz/archive/2012/01/09/asp.net-mvc-3---editing-and-updating-the-form.aspx
Vincent Maverick DuranoPosted Apr 29, 2015, 8:41 AM
The code provided should enable you to get the dropdownlist value. You should be able to insert that value to your database. You can also use ViewBag to pass the selected value to your Index. A Quick example for inserting is something like this using the traditional ADO.NET:
Then you can display the value of the ViewBag like this in your Index view:
@ViewBag.Selected
Jithil JohnPosted Apr 29, 2015, 7:23 AM
Vishwakant TripathiPosted Apr 29, 2015, 6:04 AM
can you please be more clear on how many pages you have in this scenario, and which page have dropdownlist control, and on which page you want to show it.
Jithil JohnPosted Apr 29, 2015, 5:59 AM
Vishwakant TripathiPosted Apr 29, 2015, 5:03 AM
//in above example, selectedValue is id of dropdownlist.
Jithil JohnPosted Apr 29, 2015, 4:40 AM
Vincent Maverick DuranoPosted Apr 29, 2015, 3:21 AM
As long as your DropDownList is within a form and then submit this form to an MVC action, you can grab the value that was selected from your DropDownList by it's name :
public ActionResult(string dropDownSelected){
//the dropDownSelected will contain the selected value from the list (the value of the selected option)
//Otherwise you can access it through the Request.Form collection
string selected = Request.Form["YourDropDownName"];
return View();
}
Vishwakant TripathiPosted Apr 29, 2015, 2:34 AM
@Html.DropDownListFor(model => model.selectedValue,
Let me know It helps you.
Shailesh UkePosted Apr 29, 2015, 2:18 AM
public void getdata(FormCollection fomr)
{
string name = Request.Form["name"];
}// ["name"]; is control name property