Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added using statement to the Razor Helper usage example #17040

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/docs/reference/core/Razor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Many extensions methods are available in Razor with `@Orchard`.
If you want to use an extension method in a view, you can inject an `IOrchardHelper` named `Orchard` at the top of your file:

```csharp
@using OrchardCore
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is right if it's not in the _ViewImports.cshtml

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not there by default.

@inject OrchardCore.IOrchardHelper Orchard
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for OrchardCore. here then, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did end up adding mine to the _ViewImports.cshtml instead of adding it here. Should I remove this from the usage examples and just write a comment that you might need to add the using statement?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean, the using is good, I'm talking about having@inject IOrchardHelper Orchard instead of @inject OrchardCore.IOrchardHelper Orchard, since you already import the namespace.

But otherwise yeah, you could clarify with e.g.:

// You can also put this into a _ViewImports.cshtml file so it's applied to all templates.
@using OrchardCore

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah, I misunderstood. I will remove the OrchardCore. and add the comment.

```

Expand All @@ -52,6 +53,7 @@ In `OrchardCore.DisplayManagement.Razor`, there is a RazorPage that already has
If you want to use an Orchard helper in a controller, you can inject an instance in the constructor:

```csharp
using OrchardCore;
private IOrchardHelper _orchard;

public MyClass(IOrchardHelper orchard)
Expand Down