0

I use this code to return an string from my action :

    public ActionResult Index()
    {

        string List = "";       
        List = "<table><tr><td>Ali</td></tr></table>";
        ViewData["List"] = List;
        return View();

    }

and this is my view :

<body>
<%: ViewData["List"] %>
</body>

but instead to create a table when i browse the page , i see that the string "<table><tr><td>Ali</td></tr></table>" wrote on it. I use the firebug and see its html code . but i saw something like this :

&lt;table&gt;&lt;tr&gt;&lt;td&gt;Ali&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;

Is there any body out there to help me?

Thansk Regards

4

1 回答 1

1

This is because you use the HtmlEncode tag

Change the <%: to <%=

will be come

<body>
<%= ViewData["List"] %>
</body>

and do not forget to HtmlEncode your data only to avoid any injection.

于 2012-04-17T13:14:38.327 回答