- Hi Guys,
I have a very simple form which looks like the following:
@model ContentAgent_Licensing_MVC.Models.Licensing.ViewModels.SearchViewModel @using (Html.BeginForm("FullSearch", "Search", FormMethod.Post)) { @Html.TextBoxFor(model => model.SearchTerms, new { @class = "control-textbox", @placeholder = "Search" }) <button type="submit"><img src="~/Content/images/search-icon.png" width="15" height="15" />button> }
The controller on the other end looks like this:
public class SearchController : Controller { [HttpPost] public ActionResult FullSearch(SearchViewModel SearchTerms) { return View("SearchResults", SearchTerms); } }
The model looks like this:
public class SearchViewModel { public string SearchTerms { get; set; } }
The problem is when I submit the form, the SearchViewModel object is always null when I debug into the FullSearch method. Does anyone know what I'm doing wrong...?
Many thanks
Loading
Julias NyererePosted Jul 29, 2015, 11:21 PM
Msomi Thabiso XPosted Jul 29, 2015, 11:18 PM
I think you are calling the model in the controller "SearchTerms" which matches one of the properties in the model. This might have been confusing the binder. Just change SearchTerms to Model and it might work. So the amended code will be:
Cheers