I have a index.razor file and a index.razor.cs file.
index.razor
@page "/"
@using BlazorApp8.Data
<h3>Index</h3>
<ComponentX></ComponentX>
index.razor.cs
//same story having the using outside of the namespace
//using BlazorApp8.Data;
namespace BlazorApp8.Pages
{
using Data;
public partial class Index
{
public ComponentX ComponentX { get; set; } = new ();
}
}
This is just a sample. But i have a real case that needs the using in both parts.
When I remove one of the usings in the razor part it wont work anymore. Why do I need the using two times when its a partial class?
Because a using <namespace>
directive applies to the compilation unit it is in. And that means the file.
The compiler merges the partial class definitions into one class but they remain in separate compilation units.
Nothing specific to Blazor, this is basis C#.