c# - MVC : How do I decode code to JS that was encoded in c# using JavaScriptSerializer

标签 c# javascript asp.net-mvc

我使用 System.Web.Script.Serialization 库对 C# 中的元素进行编码。 我如何从 JS 函数中解码它。

例如我有:

JavaScriptSerializer js = new JavaScriptSerializer();
string ModelString=  js.Serialize(Model);

并希望在 JS 中执行以下操作:

var element=decode('@ModelString');

最佳答案

您需要使用 jQuery。

var _Model=$parseJSON(ModelString);

然后你可以使用:

_Model.Name;
_Model.Address; //etc...

我希望这就是你想要的......

关于c# - MVC : How do I decode code to JS that was encoded in c# using JavaScriptSerializer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11444045/

相关文章:

c# - "Enable Debugging of Unmanaged Code"在哪里可以在系统运行时编辑代码?

php - 如何加密字符串数据,使其只能由其所在的计算机解码?

javascript - PHP 中的 NumberFormatter 与 JS 中的 NumberFormat

C# List.Clear() 方法没有得到正确的响应

c# - Resharper Inspection/Context Actions 不适用于一个文件

c# - 连接到单元测试中的事件

c# - 不使用 [HostType ("ASP.NET")] 测试 ASP.NET 网页

javascript - React JS 传递类作为变量

asp.net-mvc - R# "cannot resolve view"更改 ASP.net MVC2 的 View + 自定义 ViewEngine 的默认位置时

asp.net-mvc - 如何使用 EF 构建 ASP.Net MVC 应用程序?