Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8262729
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T03:51:11+00:00 2026-06-08T03:51:11+00:00

Hi all i have to get the selected value from dropdown into my post

  • 0

Hi all i have to get the selected value from dropdown into my post method in controller ..how can i do this

here is my controller

       [AcceptVerbs(HttpVerbs.Get)]
    public ActionResult AddNew()
    {          
        ViewBag.Roles = new SelectList(List(), "RoleID", "RoleName");           
        return View();
    }
    //
    //Geting All Roles In a GetRoles()/
    //
    public List<ResourceModel> List()
      {
          var roles = new List<ResourceModel>();
        SqlConnection conn = new SqlConnection("Data Source=LMIT-0039;Initial Catalog=BugTracker;Integrated Security=True");
        SqlCommand Cmd = new SqlCommand("Select GroupId,EmplopyeeRole from  EmployeeGroup", conn);
        conn.Open();
        SqlDataAdapter da = new SqlDataAdapter(Cmd);
        DataSet ds = new DataSet();
        da.Fill(ds);
        for (int i = 0; i <= ds.Tables[0].Rows.Count - 1; i++)
        {                                
            var model = new ResourceModel();
            model.RoleId = Convert.ToInt16(ds.Tables[0].Rows[i]["GroupId"]);
            model.RoleName = ds.Tables[0].Rows[i]["EmplopyeeRole"].ToString();               
            roles.Add(model);
        }
          conn.Close();
          return roles ;
      }

    //
    //To perform the AddNew Logic..i.e it adds a new employee to DB/
    //
    [AcceptVerbs(HttpVerbs.Post)]
    public ActionResult AddNew(ResourceModel model)
    {
        // var modelList = new List<ProjectModel>();
        using (SqlConnection conn = new SqlConnection("Data Source=LMIT-0039;Initial Catalog=BugTracker;Integrated Security=True"))
        {
            conn.Open();
            SqlCommand insertcommande = new SqlCommand("InsertEmplyoee", conn);
            insertcommande.CommandType = CommandType.StoredProcedure;
            insertcommande.Parameters.Add("@EmployeeName", SqlDbType.VarChar).Value = model.EmployeeName;
            insertcommande.Parameters.Add("@EmployeeEmailId", SqlDbType.VarChar).Value = model.EmployeeEmailId;
            insertcommande.Parameters.Add("@EmployeePassword", SqlDbType.VarChar).Value = model.EmployeePassword;
            insertcommande.Parameters.Add("@GroupName", SqlDbType.VarChar).Value = model.RoleName;
            insertcommande.ExecuteNonQuery();
        }
        return View();
    } 

now i want to get the selected value @GroupName Parameter in my postmethod…can any one help how to do thi

this is my html

  <%:Html.DropDownList("Roles")%>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T03:51:13+00:00Added an answer on June 8, 2026 at 3:51 am

    You could have your POST action take a view model, or add another parameter to it that will hold the selected value:

    [AcceptVerbs(HttpVerbs.Post)]
    public ActionResult AddNew(ResourceModel model, string roles)
    

    And don’t forget to repopulate the ViewBag.Roles in your POST action the same way you did in your GET action if you intend to redisplay the same view.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have read all the docs I can get my hands on and google'd
All Hadoop jobs have unique jobid. You can use jobid to get job status
Here is the query which will get me all the contacts have HD quality
trying to get my head around Feedzirra here. I have it all setup and
I have this issue trying to get all the text nodes in an HTML
This post is similar to one I have posted before about a dropdown filtering
I'm trying to get the selected value from a drop down list via jQuery.
I am trying to have 7 dropdown boxes in html. They will all get
Hi guys i have to pass the checked value from checkbox and selected value
I have to get routing direction i.e. all the lat-long location between two location

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.