c# - Help with using jQuery with ASP.NET MVC -
my app has "show comments" similar 1 in facebook. when user clicks on "show all" link, need update list has upto 4 comments comments. i'll show code first , ask questions:
jquery: showallcomments = function (threadid) { $.ajax({ type: "post", url: "/home/getcomments", data: { 'threadid': threadid }, datatype: "json", success: function (result) { alert(result); }, error: function (error) { alert(error); } }); }; home controller: // get: /getcomments [httppost] public jsonresult getcomments(int threadid) { var comments = repository.getcomments(threadid).tolist(); return json(comments ); }
questions:
when tried instead of post, got error: "this request has been blocked because sensitive information disclosed third party web sites when used in request. allow requests, set jsonrequestbehavior allowget." post recommended instead of when making these ajax requests? if not, how work get? set jsonrequestbehavior allowget?
after changing post, error: circular reference detected while serializing object of type 'models.thread'. i'm using entity framework 4, , i've read adding [scriptignore] attribute on navigation property resolve this, added partial class of entity property, said "property defined". how deal because can't directly modify code generated ef4.
set in return json. use post, if want make hard on self, use get.
public jsonresult blah() { return json("obj", jsonrequestbehavior.allowget); }
it true when orm objects serialized serialization tries searlize hidden goodies orm needs, , (sounds case) of lazy load stuff... causes bad mojo. can throw suggestion out? why not let mvc @ , generate view you? use jquery .load , use view.
Comments
Post a Comment