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"} })


Shailesh UkeRank #1,917 · 766 reputationPosted Apr 28, 2015, 10:18 PM EDT
public void getdata(FormCollection fomr)
{
string name = Request.Form["name"];
}// ["name"]; is control name property
Vishwakant TripathiRank #1,870 · 797 reputationPosted Apr 28, 2015, 10:34 PM EDT
@Html.DropDownListFor(model => model.selectedValue,
Let me know It helps you.
Vincent Maverick DuranoRank #238 · 10.3K reputationPosted Apr 28, 2015, 11:21 PM EDT
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();
}
Jithil JohnRank #2,791 · 506 reputationPosted Apr 29, 2015, 12:40 AM EDT
Vishwakant TripathiRank #1,870 · 797 reputationPosted Apr 29, 2015, 1:03 AM EDT
//in above example, selectedValue is id of dropdownlist.
Jithil JohnRank #2,791 · 506 reputationPosted Apr 29, 2015, 1:59 AM EDT
Vishwakant TripathiRank #1,870 · 797 reputationPosted Apr 29, 2015, 2:04 AM EDT
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 JohnRank #2,791 · 506 reputationPosted Apr 29, 2015, 3:23 AM EDT
Vincent Maverick DuranoRank #238 · 10.3K reputationPosted Apr 29, 2015, 4:41 AM EDT
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
Vincent Maverick DuranoRank #238 · 10.3K reputationPosted Apr 29, 2015, 4:44 AM EDT
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
vandana rathi6 reputationPosted Mar 22, 2016, 11:32 PM EDT
Vishwakant TripathiRank #1,870 · 797 reputationPosted Mar 23, 2016, 2:18 AM EDT
1.) http://stackoverflow.com/questions/20225823/jquery-ajax-callback-onchange-from-dropdownlist
2.) https://api.jquery.com/change/
vandana rathi6 reputationPosted Mar 25, 2016, 4:41 AM EDT
Vishwakant TripathiRank #1,870 · 797 reputationPosted Mar 28, 2016, 1:09 AM EDT
EmpTest
All the best.
Rohit ManeRank #2,595 · 536 reputationPosted Mar 28, 2016, 6:26 AM EDT
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
public class DocumentModel { public int TypeID { get; set; } public ListSelectListItem> DocumentTypes { get; set; } public string SelctedType { set;get;} }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.
$(function () { $("form").submit(function(){ var selTypeText= $("#TypeID option:selected").text(); $("#SelctedType").val(selTypeText); }); });Now in your
HTTPPostaction method, This will be available in theSelectedTypeproperty.Rajeev PunhaniRank #551 · 4.4K reputationPosted Jul 8, 2016, 9:46 PM EDT
If the above solution is helpful then,accept the answer.