[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2011-04-21
2
Medium Priority
?
817 Views
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" />
0
Comment
Question by:ToString1
2 Comments
 
LVL 4

Accepted Solution

by:
HohlovDima earned 2000 total points
ID: 35441729
I made sample code that works fine.
HomeController.cs:
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

Index.aspx
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<MvcApplication1.Models.Test>" %>

<!DOCTYPE html>

<html>
<head runat="server">
    <title>Index</title>
</head>
<body>
    <div>
        <% using (Html.BeginForm("Test", "Home"))
{ %>
<p>
<%: Html.DropDownListFor(x => x.ShootIdentString, (IEnumerable<SelectListItem>)ViewData["Locations"])  %>
</p>
<input type="submit" value="¿¿¿¿¿¿¿¿¿" />
<% } %>
    </div>
</body>
</html>

Open in new window

Test.cs(Model)
public class Test
{
    public string ShootIdentString { get; set; }
}

Open in new window

Best regards,
Dima.
0
 

Author Closing Comment

by:ToString1
ID: 35693433
Thanks Dima!
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Recently I spent hours debugging an issue in a Rails project where ActiveRecord was causing MySQL errors trying to create a User object of a class at the top level of a Single Table Inheritance model structure.  It turns out `.create` behaves differ…
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…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses
Course of the Month17 days, 18 hours left to enroll

830 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