Click here to Skip to main content
15,747,766 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have added a dropdown in my view and binded from database ..
now i want to get the selected value in controller how can i get that?
below is my view and controller
View :
$(document).ready(function () {
$.post("/User/GetDepartment", { actionname: "GetDepartment" }, function (data) {
var sd = "";
if (data.status == "sucess") {

}, "json").success(function () {

var sd = "";


<select id="department"></select>

public JsonResult GetDepartment()

SqlConnection con = new SqlConnection(connStr);
SqlDataAdapter cmd = new SqlDataAdapter("select * from [Department]", con);
DataSet ds = new DataSet();

var str = "";
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
str += "<option>" + ds.Tables[0].Rows[i][1].ToString() + "</option>";


return Json(new { department = str, status = "sucess" });

i would suggest you to use html helper method like:
<%=Html.DropDownListFor(x=>x.SelectedDateFormat,(SelectList)(ViewData["list"])) %>

because you would not be able to find the selected data of select - option dropdownlist on will be lost on post.
Share this answer

if Your Return Str is not empty and it may return value

than simply USed in Your Success block

if (data.status == "sucess") {


first you check what it will return using alert

I hope Your Problem Will Solve If not Please give me your Review.
Share this answer

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