C# 我可以在HTML.PartialRender()中使用变量吗?

C# 我可以在HTML.PartialRender()中使用变量吗?,c#,javascript,asp.net,.net,html,C#,Javascript,Asp.net,.net,Html,能给我一些类似于: @{HTML.PartialRender(variable);} // where variable will be a path of a file 对于RenderPartial,是否有重载 1.RenderPartial(HtmlHelper, String) 使用指定的HTML帮助程序呈现指定的局部视图 呈现指定的 局部视图,向其传递当前ViewDataDictionary的副本 对象,但将“模型”属性设置为指定的模型 呈现 指定的局部视图,将其Vie

能给我一些类似于:

 @{HTML.PartialRender(variable);} // where variable will be a path of a file
对于RenderPartial,是否有重载

     1.RenderPartial(HtmlHelper, String)
使用指定的HTML帮助程序呈现指定的局部视图

呈现指定的 局部视图,向其传递当前ViewDataDictionary的副本 对象,但将“模型”属性设置为指定的模型

呈现 指定的局部视图,将其ViewData属性替换为 指定的ViewDataDictionary对象


可以,在服务器上渲染视图时,可以使用变量作为路径参数

@{
    string path = "foo/bar"; // a path which the view engine can locate
}

<div>
    @{ Html.RenderPartial( path ); }

    @* OR *@

    @Html.Partial( path )
</div>
@{
string path=“foo/bar”;//视图引擎可以找到的路径
}
@{Html.RenderPartial(path);}
@*或*@
@Html.Partial(路径)
因为这个问题也是用JavaScript标记的,所以我要指出,不能将Razor(服务器)呈现与客户端(JavaScript)执行混合使用。但是,您可以使用AJAX轻松地调用控制器(并传递您想要的任何数据),并且该控制器可以返回渲染视图


另请参见:

使用重载:
渲染部分(HtmlHelper、字符串、对象)

例如


所以,我不能使用Javascript函数,将字符串路径返回给剃刀,对吗?这也意味着我不能使用“path”实例变量,我将从JavaScript.Correct获取路径。但是,您可以通过AJAX请求将JavaScript变量传递给控制器,并让控制器返回不同的/自定义的视图。您应该使用您尝试的代码更新您的问题(或打开另一个问题)。
     3. RenderPartial(HtmlHelper, String, 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.
@{
    string path = "foo/bar"; // a path which the view engine can locate
}

<div>
    @{ Html.RenderPartial( path ); }

    @* OR *@

    @Html.Partial( path )
</div>
@{Html.RenderPartial("PartialViewName", new { filePath = model.FilePath});}