我可以用HTML格式显示变量吗.PartialRender()
本文关键字:PartialRender 变量 显示 HTML 格式 我可以 | 更新日期: 2023-09-27 17:58:51
我能有这样的东西吗:
@{HTML.PartialRender(variable);} // where variable will be a path of a file
是的,当视图在服务器上呈现时,可以使用变量作为路径参数。
@{
string path = "foo/bar"; // a path which the view engine can locate
}
<div>
@{ Html.RenderPartial( path ); }
@* OR *@
@Html.Partial( path )
</div>
由于这个问题也用JavaScript标记,我将指出,不能将Razor(服务器)渲染与客户端(JavaScript)执行混合在一起。然而,您可以使用AJAX轻松地调用控制器(并向它传递您想要的任何数据),该控制器可以返回渲染视图。
另请参见:Html。部分与Html。渲染部分&Html。Action与Html。RenderAction
这些是RenderPartial 的过载
1.RenderPartial(HtmlHelper, String)
通过使用指定的HTML帮助程序来呈现指定的局部视图。
2. RenderPartial(HtmlHelper, String, Object)
呈现指定的部分视图,向其传递当前ViewDataDictionary的副本对象,但Model属性设置为指定的模型。
3. RenderPartial(HtmlHelper, String, ViewDataDictionary)
渲染指定的局部视图,将其ViewData属性替换为指定的ViewDataDictionary对象。
4. RenderPartial(HtmlHelper, String, Object,
ViewDataDictionary) Renders the specified partial view, replacing the partial view's ViewData property with the specified ViewDataDictionary object and setting the Model property of the view data to the specified model.
使用过载:RenderPartial(HtmlHelper, String, Object)
例如。
@{Html.RenderPartial("PartialViewName", new { filePath = model.FilePath});}