Kwasi Denkyira

Kwasi Denkyira

  • 1.5k
  • 197
  • 14.8k

Pass Data from MVC htlm Editor to a model HiddenFor field

Nov 6 2015 10:51 AM

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"];