Html.Raw(Json.En code和Internet Explorer 9 [英] Html.Raw(Json.Encode and Internet Explorer 9

查看:437
本文介绍了Html.Raw(Json.En code和Internet Explorer 9的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用 Html.Raw(Json.En code 在我的JavaScript抢传递到查看视图模型属性的内容在我的MVC 3 ASP。网(剃刀)的应用程序如下:

I use Html.Raw(Json.Encode in my Javascript to grab the contents of the ViewModel property passed to the View in my MVC 3 asp.net (razor) application as follows:

 var state = @(Html.Raw(Json.Encode(Model.State))); 

状态在我这样模型中定义

State is defined in my Model as such

 public class IndexViewModel
    {
       //..other props
        public string State { get; set; }


    }

它的工作原理就像在FF,IE8一个魅力,但在电抗器IE 9。

It works like a charm in FF, IE8 but chokes on IE 9.

有什么我应该知道上述code,它在IE 9更改,因此这不再起作用?如果是这样,这将是替代抢在你的JS视图模型的数据?

Is there anything I should know about the above code that was changed in IE 9 so this no longer works? If so, what would be the alternative to grab ViewModel data in your JS?

推荐答案

下面是一个另类

视图模型

public class StuffVM : AsSerializable
{
    public List<Stuff> StuffList { get; set; }
}

基类

public abstract class AsSerializable
{
    public string AsJson()
    {
        var serializer = new JavaScriptSerializer();
        return serializer.Serialize(this);
    }
}

查看

<script>
 var ViewModelData = @( Html.Raw(Model.StuffVM.AsJson()) );
</script>

这篇关于Html.Raw(Json.En code和Internet Explorer 9的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆