mvc2 - Post value from html dropdown in form post to controller

Posted on 2011-04-21
Last Modified: 2013-11-08
I have an ascx search control on a masterpage on an mvc2 app.  It comprises of a dropdown to select an option and then click input button.

However I cannot get it to post the selected value to the controller, what am I doing wrong

<% using (Html.BeginForm("actionName", "controllerName"))
 { %>

 <%= Html.DropDownListFor(x => x.CustomerSelectList, Model.CustomerSelectList)%>

   <input type="Submit" id="cust" value="Search" />
Question by:ToString1
    LVL 4

    Accepted Solution

    I made sample code that works fine.
    public class HomeController : Controller
        // GET: /Home/
        public ActionResult Index()
            IList<SelectListItem> list = new List<SelectListItem>();
            for(int i = 1; i < 10; i++)
                list.Add(new SelectListItem() { Text = i.ToString(), Value = (i + 10).ToString() });
            ViewData["Locations"] = list;
            return View();
        public ActionResult Test(Test test)
            return View(test);

    Open in new window

    <%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<MvcApplication1.Models.Test>" %>
    <!DOCTYPE html>
    <head runat="server">
            <% using (Html.BeginForm("Test", "Home"))
    { %>
    <%: Html.DropDownListFor(x => x.ShootIdentString, (IEnumerable<SelectListItem>)ViewData["Locations"])  %>
    <input type="submit" value="¿¿¿¿¿¿¿¿¿" />
    <% } %>

    Open in new window

    public class Test
        public string ShootIdentString { get; set; }

    Open in new window

    Best regards,

    Author Closing Comment

    Thanks Dima!

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now