Hi There,
i'm having a problem passing a model with array to the HttpPost action.
i have this code:
public class Service
{
public string name { get; set; }
public ServiceProblem[] problems { get; set; }
}
[HttpGet]
public JsonResult AutoCompleteServiceProviders(string query)
{
List<Object> services = GetServices();
List<Service> servicesList = new List<Service>();
foreach (var item in services)
{
servicesList.Add((item as Service));
}
var result = servicesList
.Where(c => c.name.ToLower().StartsWith(query))
.Select(c => new { Value = c.name, Label = c.name, p = c.problems });
return Json(result, JsonRequestBehavior.AllowGet);
}
when debugging the Lambda expression i can clearly see the c.problems has the ServiceProblem[]
the js code, manages the data:
$.ajax({
url: requestUrl,
dataType: "json",
data: { query: request.term },
success: function (data) {
response($.map(data, function (item) {
return {
label: item.Label,
value: item.Label,
realValue: item.Value
};
}));
},
});
but when i get into the
[HttpPost]
public ActionResult Index(Service fxService)
{
return RedirectToAction("Select", "Create", fxService);
}
the fxService has two object, one the currect name of the selection form the view
but the "problems" object is null.
also the .cshtml code:
@using (Html.BeginForm("Index", "Create"))
{
<fieldset> @Html.AutocompleteFor(Url.Action("AutoCompleteServiceProviders", "Create"), true, "ex. Shower", c => c.name, c => c.problems)
<input type="submit" id="search" value="" />
</fieldset>
}
kindly your help.