I want to pass a parameter (string) to my Controller from my View. The value should be that which is selected from a dropdown list in the view. The method is called after a button-click, but in the Controller, the parameter is always null.
In the View:
@using (Html.BeginForm("Send", "Overview", FormMethod.Get))
{
<p>Email: @Html.DropDownList("Emails", Model.GetEmails())
<input type="submit" value="Send" />
</p>
}
In the Controller:
public ActionResult Send(string email)
{
// email is always null!
return null;
}
In the Overview model:
private List<SelectListItem> emails;
...
public Overview()
{
emails = new List<SelectListItem>();
emails.Add(new SelectListItem() { Text = "a@b.com", Value = "a@b.com", Selected = true });
emails.Add(new SelectListItem() { Text = "b@c.com", Value = "b@c.com", Selected = false });
emails.Add(new SelectListItem() { Text = "c@d.com", Value = "c@d.com", Selected = false });
}
...
public List<SelectListItem> GetEmails()
{
return emails;
}
Could you please help me get this work? What am I missing? (Btw, never mind the Controller returning null for now please :)).