I'm trying to recreate the following JavaScript code using Newtonsoft's parser:
var nav = { container: $('.ux-navigation-control'), manual: true, validate: true };
Trying to use Html.Raw
inside Newtonsoft like:
var nav = @(new HtmlString(JsonConvert.SerializeObject(new
{
container = Html.Raw("$('.ux-navigation-control')"),
manual = true,
validate = true
}))) ;
Returns an empty object inste开发者_如何学Goad of the desired expression:
var nav = {"container":{},"manual":true,"validate":true} ;
Any help?
$('.ux-navigation-control')
isn't valid JSON, so most if not all JSON parsers will throw this out. You should just return the selector instead and do some post-processing on the client side, like so:
$.getJSON('/myurl', function(nav) {
nav.container = $(nav.container);
// do something else with nav
});
精彩评论