0

I have a dynamic dropdrownlist and I want to pass selected value from dropdown to controller

ModelBEL.cs

public class ModelBEL
{
    public static string exmId { get; set; }
    public static string qus { get; set; }
    public static string ans1 { get; set; }
    public static string ans2 { get; set; }
    public static string ans3 { get; set; }
    public static string ans4 { get; set; }
    public DataSet exmAllData { get; set; }
}

Database layer class

public class dbEngine
{
    SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ConnectionString);
    SqlCommand cmd = null;
    SqlDataAdapter sda = null;
    DataSet ds = null;

    public DataSet getExamQus()
    {
        sda = new SqlDataAdapter("usp_getAllExam", con);
        ds = new DataSet();
        sda.Fill(ds);
        return ds;
    }
}

View

<select id="ddl1">
    <option>select</option>
    @for (int i = 0; i < @Model.exmAllData.Tables[0].Rows.Count; i++)
    { 
        <option>@Model.exmAllData.Tables[0].Rows[i][0].ToString()</option>
    }
</select>

I use dropdown as

@Html.DropDownList("exam", "choose Tournament")

How can I pass selected value from dropdown to controller

  • 1
    What is the `name` of the `select` element? That's the key for the value being passed to the model binder. As long as the controller action has a matching parameter by that name or the model binder can find one on the model, that's where the value will be. – David Nov 20 '14 at 18:51
  • You need to invest some time in learning the basics of HTML, MVC and model binding. You have manually created a ` –  Nov 20 '14 at 23:09

0 Answers0