Search code examples
razorasp.net-mvc-4

Wanting to insert cshtml inside cshtml in ASP.NET MVC4, similar to usercontrol in webforms


What is the best way to insert re-usable code into a cshtml razor file. I need to pass in data from the outer loop into the user control. I took a picture of what I'm trying to do hoping that will make it very clear.

enter image description here


Solution

  • Use

    @Html.RenderPartial(<virtual path to your partial view>, session);
    

    where partial view is typed view with the model of session type.