Click here to Skip to main content
15,941,828 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using a dropdownlist with some static values in webgrid. and i want to pass a unique ID along with dropdownlist value to action method. How can i do this? I am using below code but its not working. @item.MessageId is the value i want to pass to an action method along with dropdown selected value. and how i can get that value in action?

HTML
@using (Html.BeginForm("ChangeMessagePriority", "Home", FormMethod.Post, new { id = @item.MessageId }))
{
  @Html.DropDownList("ddlPR1", listItems, new { onchange = "this.form.submit();" })
}
Posted
Updated 15-Sep-15 1:43am
v3

1 solution

Use a hidden field

C#
@using (Html.BeginForm("ChangeMessagePriority", "Home", FormMethod.Post, new { id = @item.MessageId }))
 {
   <input type="hidden" value="myhiddenvalue" />
 @Html.DropDownList("ddlPR1", listItems, new { onchange = "this.form.submit();" })
 }


how that value is populated depends on where the data is coming from. You can also make it part of the model and use Html.HiddenFor(m => m.MyHiddenValue)
 
Share this answer
 
Comments
Sumit Thakur 15-Sep-15 8:11am    
thanks man

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900