Skip to content Skip to sidebar Skip to footer

Could Not Pass Dropdownlist Selected Value To Action Method

I have used a ModelView for static Dropdownlist values and tried to call print method from Razor in MVC4. However, I cannot pass the selected Dropdownlist value to teh Action metho

Solution 1:

ApplicantViewModel:

`public class StaticList{

    public string type { get; set; }

    public List<SelectListItem> DropdownList { 
        get {
                return new List<SelectListItem> 
                {
                    new SelectListItem { Selected = false,Value = "pdf", Text = "Pdf" },
                    new SelectListItem { Selected = false,Value = "excel", Text = "Excel" },
                    new SelectListItem { Selected = false,Value = "word", Text = "Word" }
                };
            }
    }
}`

ApplicantController:

 public  ActionResult Test(StaticList list)
    {
        list.type = "pdf";
        return View(list);
    }

Reporting.cshtml:

@Html.DropDownListFor(model => model.type, Model.DropdownList)

Everything works fine for me.


Solution 2:

Name you dropdown list must be equals parameter name in your Action.

Edit: I repeat you code, all work fine if RenderReport have string SelectedValue parameter

public ActionResult RenderReport(string SelectedValue, string name, string fileName, string dataSource, string table, string filter)
{
    //Codes for rendering report
    ...
}

or Use @Html.DropDownList and set custom Name for DropDownList

 @Html.DropDownList("type", Model.Values, "-- select an option --", new {id = "type"})

Post a Comment for "Could Not Pass Dropdownlist Selected Value To Action Method"