Bevygixedge
New Member
I have a search page that uses a complex model. I would like to use Ajax to post back only the criteria but when I do, the html field names all contain the \[code\]Criteria\[/code\] prefix which causes the modelbinding for the \[code\][HttpPost]Search\[/code\] method to fail. The View looks roughly like this:\[code\]@model ViewModel @using(Html.BeginForm(...)){ @Html.EditorFor(x => x.Criteria.SearchText) <button>Search</button>}@{Html.RenderPartial("Results", Model.Results);}\[/code\]And my supporting controller and classes look like this:\[code\]public class ViewModel{ public Criteria Criteria { get; set; } public IList<Result> Results { get; set; }}public class Criteria { /* Complex Model */ }public class Result { /* Complext Model */ }public ActionResult Search(){ return View(new ViewModel());}[HttpPost]public ActionResult Search(Criteria criteria){ var results = service.Search(criteria); return PartialView("Results", results);}\[/code\]I have considered using the HtmlHelperFor<> implemention suggested in this question, but I was hoping there was a cleaner solution. Whats the general consensus?Thanks in advance.