mvc中html对象的方法吗,在MVC中使用jQuery模板进行HTML编码的Json对象

本文介绍了一个使用MVC、jQuery和Ajax技术实现的网站评论系统。该系统允许用户即时发布评论,并通过jQuery模板实时更新页面上的评论内容。文章详细展示了如何在服务器端处理评论数据并返回JSON格式的结果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

所以我有能力在我的网站上发表评论。用户进入场命中“后”和我阿贾克斯评论回到其在该行动的结果在MVC中使用jQuery模板进行HTML编码的Json对象

public ActionResult PostComment(Comment NewComment)

{

var repository = GetRepository();

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

}

这是reuturned我的jQuery处理它的数据库,它使用jQuery的模板,显示在评论页面

$.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;

}

});

对我有任何进入用户输入回发下来的时候将被转换为

但jQuery的模板,把他们拖到页面上在众目睽睽之下,而不是被只是部分HTML编码问题的一些原因的代码

有什么我需要打开/关闭?

2011-04-05

Steve

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值