Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在视图中,我有一个 Razor 代码,例如
@Code Dim x As String = "MyTest" End Code
但是,如何在不将其复制/粘贴到所有视图中的情况下与其他视图共享该代码?
您可以创建局部视图,然后使用以下代码在其他页面上呈现局部视图:
@Html.RenderPartial("Path to partial view")
您还可以通过包含第二个参数将模型传递给强类型分部视图:
@Html.RenderPartial("Path to partial view", myModel)