This question has probably been asked before but my search failed to turn anything up. Is there an easy way to find out whether a view/partial is not being used in an MVC project? Currently I'm searching for the individual view name across the entire solution but wondering whether there's a tool out there that would make this job easier? I'm ideally looking for something that would provide a visual indication within Visual Studio if a view/partial is not being used.
I'm basically cleaning up an existing codebase and want to rip out any views that are not being used any more.
A partial view is a Razor markup file ( . cshtml ) without an @page directive that renders HTML output within another markup file's rendered output. The term partial view is used when developing either an MVC app, where markup files are called views, or a Razor Pages app, where markup files are called pages.
A partial view is sent via AJAX and must be consumed by JavaScript on the client side, while a View is a full postback. That's it. Normally this means that a View is more of a complete web page and a partial view is reserved for individual sections or controls. Realistically, though, you can send the exact same .
Rendering a Partial View You can render the partial view in the parent view using the HTML helper methods: @html. Partial() , @html. RenderPartial() , and @html. RenderAction() .
When I want to see if a view is used, I move it out of my project and enable view compilation. If a view is referenced from somewhere else it usually breaks.
enable view compilation by manually editing your mvc csproj file and setting the following
<PropertyGroup>
<MvcBuildViews>true</MvcBuildViews>
</PropertyGroup>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With