0
Answer

Pass Data from MVC htlm Editor to a model HiddenFor field

I am doing an Autocomplete in Mvc . After a user search and populate an Editor Box and hit OK, I want to send the data to hiddenFor model to save in the sql server database.

I am doing something like this but is not working.

<td>
@Html.Editor("SearchString", null, new { id = "SearchString1", @style = "width: 400px; Height: 40px" })
@Html.HiddenFor(model => model.SelectedUsers, new { @id = "Hidden1" })
<p>Enter users to begin searching</p>
</td>

Then in the controller

ItemSelected.SelectedUsers = ViewData["SearchString"];