Click here to Skip to main content
15,867,906 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Everyone

i am trying to get a selected value from drop down list

1st have taken all inputs value from form using FormCollection in that from the from id now i want take the value of the selected dropdown list

till i have done

my cshtml is i have check box and dropdown list

XML
<td><input type="checkbox" name="'chk#'@item.CountryDetails.CountryId" id="'chk#'@item.CountryDetails.CountryId"  /></td>
                                  <td><select id="'DRP#'@item.CountryDetails.CountryId" name="'DRP#'@item.CountryDetails.CountryId"><option value="null">--Select time--</option>
                                  <option value="monthly">Monthly</option>
                                  <option value="yearly">Yearly</option>



in controller i ma writing

C#
List schObj = new List();// this is the created Class in model
Scheduling WSH = new Scheduling();

for (int i = 0; i < form.Count; i++)
{

if (form[i] == "on")
{
WSH.Scheduled = true;
string CID = form.AllKeys[i];
string[] splitnum = null;
splitnum = CID.Split('#');
CID = splitnum[1].ToString();
CID = CID.Replace("'", "");
WSH.CountryId = Convert.ToInt64(CID);

schObj.Add(WSH);
}


now i want get the selected value from dropdown list
Posted
Updated 31-Aug-14 19:59pm
v2
Comments
Jameel VM 1-Sep-14 2:43am    
How your are filling the drop down list? can you please post that code ?

1 solution

You can get selected value from dropdownlist using formcollection
Example:
public ActionResult Create(FormCollection collection)
      {
          try
          {
               int Country = Convert.ToInt32(collection["Country"]);
               int State = Convert.ToInt32(collection["State"]);
               int City = Convert.ToInt32(collection["City"]);
              return RedirectToAction("Index");
          }
          catch
          {
              return View();
          }
      }


Where collection["Country"], Country is dropdown Control ID etc
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900