2

我可以有类似的东西:

 @{HTML.PartialRender(variable);} // where variable will be a path of a file
4

3 回答 3

1

是的,当视图在服务器上呈现时,您可以使用变量作为路径参数。

@{
    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.Partial vs Html.RenderPartial & Html.Action vs Html.RenderAction

于 2013-02-11T14:44:06.810 回答
0

这些是 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.
于 2013-02-11T14:38:26.347 回答
0

使用重载: RenderPartial(HtmlHelper, String, Object)

例如。

@{Html.RenderPartial("PartialViewName", new { filePath = model.FilePath});}
于 2013-02-11T14:45:22.523 回答