Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Discover whether views/partials are being used within an MVC project

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.

like image 555
levelnis Avatar asked Jun 06 '13 09:06

levelnis


People also ask

Can you define partial view in MVC?

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.

How do you find partial view?

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 .

Which of the following methods are used to render partial view in MVC?

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() .


1 Answers

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>
like image 171
spaceman Avatar answered Oct 24 '22 04:10

spaceman