I have a model as follows:
public class SearchModel
{
public List<CheckBoxResponse> Status { get; set; }
}
public class CheckBoxResponse
{
public string ItemText { get; set; }
public bool Selected { get; set; }
}
The view is as follows:
<div id="divSearchParams">
<div class="col-xs-12 col-sm-12 col-md-5 col-lg-5">
<div class="form-group">
<label>Status</label> <br />
@for (var i = 0; i < Model.Status.Count; i++)
{
<input type="checkbox" asp-for="@Model.Status[i].Selected" />
<label asp-for="@Model.Status[i].Selected">@Model.Status[i].ItemText</label>
<input type="hidden" asp-for="@Model.Status[i].ItemText" />
}
</div>
</div>
</div>
My AJAX call :
$(document).on("click", "#search", function () {
var model = $('#divSearchParams').find("input,select,textarea").serialize();
$.ajax({
url: targetUrl,
type: 'POST',
data: { model: model },
cache: true,
async: true,
}).done(function (result) {
}).fail(function (error) {
}).always(function () {
}
});
});
So on serialise, the model value is "Status%5B0%5D.ItemText=Open&Status%5B1%5D.Selected=true"
However when I check the value of model in controller, I see Status value inside model is null.
public async Task<ActionResult> Students(SearchModel model)
{
}
What am I missing?

Students()parameter type fromSearchModeltostringyou will see what you are sending, at least.