I need to get json object from string and return it from controller.
In my Controller I have second thing:
[HttpGet]
public JsonResult GetPageFilters()
{
...
...
if (settings != null)
{
var data = JsonConvert.DeserializeObject(settings.Filters); //Filter is string with json
return Json(data);
}
else
{
return null;
}
}
and this in my view:
var filterOption;
$.get('Library/Books/GetPageFilters', null, function(data) {
filterOption = data;
}, "json");
Controller are called normally, string is deserialized to object... but function(data)
is not working. Nothing are happening there and I cant get why.
What am I missing?
EDIT:
Looks like string to json went wrong. I tried to save it in database what looks fine i guess, but read it properly is a problem to me.
function UpdateFilter() {
var filterOption = {
"filterTarget": "Books",
"filters": [
{ "cancelled": $("#showCancelledFilter").is(':checked') },
{ "completed": $("#showAllFilter").is(':checked') }
],
"page": page,
"sorting": sorting
};
var url = "Library/Books/UpdateFilter";
$.post(url, { pageFilters: JSON.stringify(filterOption) }, function (data) { });
}
seems working fine, but as I told already, from string to json is not ok for some reason.