Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: MVC
How To Pass Dropdownlist Selected Value from View To Controller in mvc....
Posted 14-Mar-11 4:11am
Comments
E$w@r at 14-Mar-11 13:13pm
   
are tried in google?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

check this and this. I am sure it will help Smile | :)
  Permalink  
Comments
Dalek Dave at 18-Mar-11 18:10pm
   
Good Links.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

By using hidden field u easily access value in controller
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

Hey,
 
You can also do in this way. Create an view which will be strongly typed.
 

@model YourClassViewModel
@using (Html.BeginForm())
{
Security :
@Html.DropDownListFor(x => x.SelectedSecurityId ,new SelectList(Model.Securities, "Value", "Text"),"Select one")

 
CUSP:
@Html.DropDownListFor(x => x.SelectedCUSIPId ,new SelectList(Model.CUSIPs, "Value", "Text"),"Select one")

 
<input type="submit" value="Save" />
 
}
 
[HttpPost]
public ActionResult GetThat(YourClassViewModel objVM)
{
   // You can access like objVM.SelectedSecurityId
   //Save or whatever you do please...
}
 

After submitting an action you will get that selected dropdown value in param object.
 
--SDK
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 6

@Html.DropDownListFor(p=>p.nmae,(SelectList)ViewBag.Name, "---Select---",
new { id =dlBillStatus", })
 
this will do...!!!
 
the thing you hav to pass selected value in this viewbag..!!
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

<![CDATA[<%= Html.DropDownList("REGDNOO", (IEnumerable<SelectListItem>)ViewData["REGDNOO"], "--Select--", new { onchange = "document.location.href = 'CategoryDetails/CategoryDetails?id=' + this.options[this.selectedIndex].value;" })%>]]>
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

if you bind model to view you will get the selected value directly in controller
 
(without binding the model also we can achieve the selected value from ajax hit)
 
1.tell me few things have you bind any model to the view in which your dropdown exist.?
 
2. did you write post action method in controller?
 

//in view
<% using (Html.BeginForm())
               { %>
            
            <%=Html.DropDownListFor(m => m.CourseId, new SelectList((ViewBag.Courses) as SelectList, "Value", "Text"), "Select")%>
            
            <input id="submit" type="button" value="Save" name="submit" />
            <%} %>
 
//in document.ready
$("#submit").live("click", function (e) {
                
                e.preventDefault();
                var data = JSON.stringify({ CourseId: $('#CourseId').val()});
                $.ajax({
                    type: "POST",
                    url: config.basePath + '/Controllername/ActionMethodName',
                    cache: false,
                    data: data,
                    dataType: this.dataType,
                    contentType: "application/json; charset=utf-8",
                    success: function (result) {
 
                        if (result.IsSuccess) {
                            $("#error_message").html(result.ErrorMessage);
                            $("#error_message").addClass("success");
                            UTMSGrid.StudentCourses.List.bindGrid($("#grid"));
                        }
                        else {
                            $("#error_message").html(result.ErrorMessage);
                            $("#error_message").addClass("fail");
                        }
                    },
                    error: function (data) {
                        // $("#error_message").html(data);

                    }
                }); // End ajax call

 

            });
 
//in controller
[HttpPost]
        public JsonResult ActionMethodName(ModelName model)
        {
        int id=   model.CourseId //contains selected courseid
            return Json(id, JsonRequestBehavior.AllowGet);
        }
  Permalink  
v3
Comments
indu2012 at 27-Sep-12 11:41am
   
i have 3 drop down in result page .if he select a value from any drop down the result will be filler ?how i do this in mvc3

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 392
1 OriginalGriff 370
2 CPallini 190
3 Abdul Samad KP 145
4 George Jonsson 119
0 OriginalGriff 6,329
1 Sergey Alexandrovich Kryukov 5,700
2 CPallini 4,940
3 George Jonsson 3,469
4 Gihan Liyanage 2,522


Advertise | Privacy | Mobile
Web01 | 2.8.140916.1 | Last Updated 4 Sep 2013
Copyright © CodeProject, 1999-2014
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