Reputation: 1
i need to send selected dropdown item text, not value, to controller. Here is the view code
@using (Html.BeginForm("Index", "Home"))
{
<div class="container">
<div class="form-group">
@if (ViewBag.CountryList != null)
{
@Html.DropDownListFor(model => model.CountryId, ViewBag.CountryList as SelectList, "choose country", new { @class = "form-control" })
}
</div>
<button type="submit">Send</button>
</div>
}
In controller i tried to access the request context of the submitted form, but it returns the value, not the text of selected item. Please help to retrieve the text of selected dropdown item to controller.
Upvotes: 0
Views: 655
Reputation: 262
You can pass Id
and Value
field from Value
property of your ViewBag
Try this :
@Html.DropDownListFor(x => x.CountryId, new SelectList(@ViewBag.CountryList, "Value", "Value"), new { @class = "form-control" })
Upvotes: 1
Reputation: 304
Just pass you model (replace YourModel with you model)
[HttpPost]
public ActionResult Index(YourModel objModel)
{
var CountryId = objModel.CountryId
}
Upvotes: 0