Sumudu De Zoysa
Sumudu De Zoysa

Reputation: 253

How to pass string value of MVC DropDownList as a parameter to method in controller?

 @Html.DropDownList("CourseField", new SelectList(SmartJob.Web.UI.Helper.ProfessionalCourseDropDownHelper.CourseCategoriesDropDown, "Key", "Value", 0), "Field of Study")

I want to pass the selected record as a parameter to a method in my contoller. How can I pass that value?

This is the method in my controller.

public PartialViewResult SearchCourseCriteria(string CourseField){

}

Upvotes: 2

Views: 1216

Answers (1)

teo van kot
teo van kot

Reputation: 12491

If you use form post like this:

<form method="get" action="/YourController/SearchCourseCriteria">
    @Html.DropDownList("CourseField", new SelectList(SmartJob.Web.UI.Helper.ProfessionalCourseDropDownHelper.CourseCategoriesDropDown, "Key", "Value", 0), "Field of Study")
<button>Submit<button />
<form />

Then your controller will be like this:

public PartialViewResult SearchCourseCriteria(string CourseField)
{
...//Controller logic here
}

Depending on your value type in DropDown it could be not string, but int or anythig else...

Upvotes: 1

Related Questions