Click here to Skip to main content
11,931,104 members (59,494 online)
Rate this:
Please Sign up or sign in to vote.
See more: MVC
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" });
Posted 14-Jan-13 20:34pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2


if Your Return Str is not empty and it may return <option>value</option>

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.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web04 | 2.8.151126.1 | Last Updated 18 Jan 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100