防止在 HTML 中呈现 ID 值

Prevent ID value being rendered in HTML

我有一个要保存到 ViewBag 的 ID 值:

ViewBag.MyID = 1

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

if (table.id === @ViewBag.MyID)
    //Do stuff

这工作正常,但呈现的 HTML 包含实际 ID:

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

有什么办法可以避免这种情况吗?我需要在客户端执行此操作。

    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

@Html.HiddenFor(模型 => model.ID)

通过jQuery加密

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

参考:MD5 Encryption using jQuery