开发者

Dynamically built Javascript src attribute error in IE

开发者 https://www.devze.com 2022-12-15 01:02 出处:网络
Controller public ActionResult GetCategories() { var htmlText = new StringBuilder(); var scriptText = new StringBuilder();

Controller

public ActionResult GetCategories()
    {

        var htmlText = new StringBuilder();
        var scriptText = new StringBuilder();

        htmlText.Append("Hello world");
        scriptText.AppendFormat("document.write({0});", htmlText.ToString());
        var content = new ContentResult();
        content.Content = scriptText.ToString();
        return content;
    }

View

<script src="/Home/GetC开发者_开发百科ategories" type="text/javascript" language="javascript"/>

It runs well on FF, but not in IE.


A script tag needs a closing tag to be compliant. IE actually obeys the standard in this respect while FF is more forgiving. Change your view to:

<script src="/Home/GetCategories" type="text/javascript" language="javascript">
</script>
0

精彩评论

暂无评论...
验证码 换一张
取 消