防止在HTML中呈现ID值

时间:2017-04-05 07:11:59

标签: jquery asp.net-mvc viewbag

我有一个ID值,我将其保存到ViewBag:

if (table.id === 1)
    //Do stuff

然后我想在jQuery中使用该ID来检查我的MVC应用程序的客户端上的某些内容:

public void setChatMsgList(List<ChatMsg> chatMsgList ) {
    this.chatMsgList = chatMsgList;
}

这很好用,但呈现的HTML包含实际的ID:

{
    ...
    chatMsgList.add(chatMsg); 
}
imAdapter.setChatMsgList(chatMsgList);
imAdapter.notifyDataSetChanged();

有什么方法可以阻止这种情况吗?我需要在客户端这样做。

3 个答案:

答案 0 :(得分:1)

    As per your requirement,what i understand is you don't want to display ID 
   value in rendered html output.
   So to prevent this use Code Level Encryption/Decryption.
   While sending the values to View encrypt them and compare.
 --> I think it may help you. Thank You

答案 1 :(得分:0)

@ Html.HiddenFor(model =&gt; model.ID)

答案 2 :(得分:0)

通过jQuery加密

var strMD5 = $.md5(@ViewBag.MyID);

参考:MD5 Encryption using jQuery