开发者

How can I have Raw HTML inside a JsonConvert's SerializeObject()?

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
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜