0

So I have the ability to post comments on my site. User enters a field hits "post" and i ajax the comment back to the database which is dealt with it in this Action result

public ActionResult PostComment(Comment NewComment)
    {
        var repository = GetRepository<Comment>();
        var player = GetPlayer();
        //we have this stuff
        NewComment.Created = DateTime.Now;
        NewComment.Updated = NewComment.Created;
        NewComment.Live = true;
        NewComment.Player = player;

        repository.Add(NewComment);

        return new JsonResult { Data = new { Success = true, Comment = new CommentSummary(NewComment, player) } };
    }

This is the reuturned to my jquery which uses jquery template to display the comment on the page

 $.post("/comments/PostComment", data, function(json) {
        if(json.Success){              
            var newComment = [
              {
                Id: json.Comment.id,
                postedOn: json.Comment.postedOn,
                postedBy: json.Comment.postedBy,
                body: json.Comment.body
              }
            ];

            /* Compile markup string as a named template */
            $.template("TmplComment", $("#CommentTemplate").html());

            /* Render the named template */
            $.tmpl("TmplComment", newComment).prependTo("#AllComments");

            //Do some tidying
            $('#Comments_HasComments').show();
            $('#Comments_HasNoComments').hide();
            $("#frmPostComment textarea[name='comment']").val('')

            //go to your comment
            $("#Comment_" + json.Comment.id).animate({backgroundColor: "#F4FF8C"}, 1000 ).animate({backgroundColor: "#ffffff"}, 1000 );
            location.href = "#Comment_" + json.Comment.id;
        }                        
    });

for some reason I am having HTML encoded issues as any enters the user has entered will be converted to
when posted back down but the jquery template puts them onto the page in full view instead of being just part of the code

is there something i need to turn on/off??

1 Answer 1

1

Are you using the {{html}} template tag for the comment body?

Sign up to request clarification or add additional context in comments.

1 Comment

perfect and you have opened my eyes up to alot more jquery template stuff thanks!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.