0

In a View, I have a Razor code like

@Code

    Dim x As String = "MyTest"

End Code

However, how can I share that code with other Views without copy/paste it in all the Views?

Levi Botelho
  • 24,626
  • 5
  • 61
  • 96
Max
  • 4,965
  • 17
  • 49
  • 64

1 Answers1

1

You can create a partial view, and then use the following code to render the partial view on your other pages:

@Html.RenderPartial("Path to partial view")

You can also pass a model to a strongly-typed partial view by including a second parameter:

@Html.RenderPartial("Path to partial view", myModel)
Levi Botelho
  • 24,626
  • 5
  • 61
  • 96