将HTML字符串从控制器传递到View ASP.Net MVC [英] Pass Html String from Controller to View ASP.Net MVC
本文介绍了将HTML字符串从控制器传递到View ASP.Net MVC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是将HTML字符串块从Controller传递到MVC中的View的最佳方法.我希望它在页面加载时显示该html块.谢谢你.可以是任何HTML 例如
Which is the best way to pass the Html String block from Controller to View in MVC. I want it display that html block at the page load. Thank you. It can be any Html, e.g
<table style="width:300px">
<tr>
<td>Jill</td>
<td>Smith</td>
<td>50</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
</table>
我想将此作为字符串从控制器传递给View.它将显示为html的位置. 谢谢.
I want to pass this as a string from controller to View. where it will be displayed as an html. Thank you.
推荐答案
在您的控制器操作中:
ViewBag.HtmlStr = "<table style=\"width:300px\"><tr><td>Jill</td><td>Smith</td> <td>50</td></tr><tr><td>Eve</td><td>Jackson</td><td>94</td></tr></table>";
您的视图:
@Html.Raw(ViewBag.HtmlStr)
这篇关于将HTML字符串从控制器传递到View ASP.Net MVC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文