次のようなものがありますか?
@{HTML.PartialRender(variable);} // where variable will be a path of a file
次のようなものがありますか?
@{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.Partial と Html.RenderPartial および 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});}