ReSharper provides the following code analysis and coding assistance features for ASP.NET and ASP.NET MVC projects.
ReSharper highlights various symbols in ASP.NET markup, so that it is easy to distinguish them.
It also provides syntax highlighting for C# and VB.NET code blocks.
Various code inspections are available for ASP.NET, including detecting unused import namespaces,
unknown symbols and entities, etc. You can set a severity level for each inspection.
For more information, see Configuring ReSharper
To navigate between code issues that ReSharper discovers, use marker bar and status indicator.
Code completion in ASP.NET enables you
to work with different language constructs. You can complete tags, attributes and their values:
ASP.NET markup can contain blocks of code within tags, so ReSharper provides completion for symbols within such blocks:
Strongly-typed data controls
Some new enhancements that improve and simplify the work with data are introduced in ASP.NET 4.5.
One of them is strongly typed data controls and model binding. ReSharper started providing
the corresponding inspections, quick-fixes and other features as soon as these controls were introduced.
Consider the example below:
Code completion features are available for the new attribute. You use the ItemType attribute to specify what type of data the control is going to be bound to and ReSharper suggests the types that are appropriate.
After the type is set you can use Item and BindItem properties and get all benefits of using ReSharper as well.
During code analysis ReSharper detects and highlights symbols that can't be resolved
because the appropriate Import or Register
directives are missing. Also, it offers an easy way to add such directives and fix the problem.
ReSharper adds a necessary Import directive for .NET symbols:
Or a necessary Register directive for ASP.NET controls:
For more information, see Importing Namespaces.
Examples of context actions
More than 25 context actions for ASP.NET are available to replace, collapse or remove tags, convert HTML entities, create events and properties, add code-behind files, etc. See context actions in ASP.NET for the full list of context actions.
If you use a function that has not been declared yet, ReSharper prudently suggests you to add a function declaration to the current file.
Add code-behind file
If the corresponding attribute is missing, ReSharper either creates a code-behind file and adds the attribute or just adds the attribute if the file already exists.
Examples of quick-fixes
If the corresponding Import directive is missing, ReSharper suggests this quick-fix.
After applying the quick-fix, the necessary directive is added.
ReSharper informs you that the ChangePasswordPushButton_Click method doesn't exist...
...and offers to create one.
The method declaration is inserted into the code-behind file or into the current file depending on web page code model (single-file page model or code-behind page model).
The signature of the ChangePasswordPushButton_Click method doesn't match the signature of the OnClick event.
ReSharper offers a quick-fix to change the signature of the method:
Remove unused directives in file
ReSharper detects unused import namespace directives.
As they are unnecessary ReSharper suggests a quick-fix that removes all of them from the current file.
Add Inherits attribute
This quick-fix is specific for ASP.NET directives. The CodeFile attribute is used together with the Inherits attribute to associate a code-behind source file with a user control or a page. When the latter is missing, ReSharper suggests a quick fix:
If there is a Content control on a content page that is mapped to a missing ContentPlaceholder on the master page, ReSharper suggests creating the corresponding ContentPlaceholder control on the corresponding master page.
The ContentPlaceholder control with the corresponding ID attribute is added to the master page:
Using this feature you can easily move code structures or parts of them.
For example, you can move tags up or down, attributes to the left or to the right.