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

Cannot use HtmlHelper from view #22

Closed
lasrol opened this issue Oct 25, 2016 · 14 comments
Closed

Cannot use HtmlHelper from view #22

lasrol opened this issue Oct 25, 2016 · 14 comments

Comments

@lasrol
Copy link

lasrol commented Oct 25, 2016

Using @Html.Raw("<span>test</span>") returns a TemplateCompilationException.
With internal error message "The name 'Html' does not exist in the current context".

I assume you need to setup the HtmlHelper() for it to work?
Any other way i can pass inn a Html string from a model?

@toddams
Copy link
Owner

toddams commented Oct 25, 2016

RazorLight has no HtmlHelpers support. So for Raw encoding use our own iimplementation of this

@Raw("Enter your text here")

@lasrol
Copy link
Author

lasrol commented Oct 25, 2016

Yes, this works 👍 but it is a bit ugly since VS returns an error and red squiggly line. Anyway to tell VS that this is correct? a using statement?

Error CS0103 The name 'Raw' does not exist in the current context

@toddams
Copy link
Owner

toddams commented Oct 25, 2016

Visual studio tries to use built-in Razor tooling, that's why it shows you errors, as it knows nothing about RazorLight

@lasrol
Copy link
Author

lasrol commented Oct 25, 2016

I understand :) but are you aware of anyway i can supress this error message for this exact line to ensure others does not get confused because of this error?

That will require an extension to VS?

@toddams
Copy link
Owner

toddams commented Oct 25, 2016

I will add html helpers support in the future, so you won't see this annoying errors, but for now - you should deal with it)

@jjxtra
Copy link

jjxtra commented Mar 1, 2019

It's been 2.5 years, still no html.raw capability. What is needed to add this?

@jmevel
Copy link

jmevel commented Apr 19, 2019

I feel many issues in RazorLight repo have been closed while they actually shouldn't have been.
This should have stayed open in the backlog, instead it was closed and 3 years later we are still waiting for it...

@jjxtra
Copy link

jjxtra commented Apr 19, 2019

I moved on to just using regular razor, it was not very difficult. Using it in my MIT licensed mail sender project.

https://github.com/DigitalRuby/MailDemon/blob/master/Services/RazorRenderer.cs
https://github.com/DigitalRuby/MailDemon/blob/master/Services/ViewRenderer.cs

@jmevel
Copy link

jmevel commented Apr 19, 2019

Thanks. I've made a quick mail sender component as well for my company. Now this is already done using RazorLight we will stick with it for the moment but for sure I won't choose RazorLight ever again in the future

@martinalderson
Copy link

FWIW, this is a real problem on .NET core. Visual Studio will always try to compile .cshtml files (even using the nuget package to disable this), and @Raw doesn't compile using normal razor syntax. The only way I could do it was use @Html.Raw in cshtml files, then load the files manually into strings, replacing @Html.Raw with @Raw. It's a shame @Html.Raw could not have been implemented, all the rest are nice to haves but this is a real issue which involves pretty horrible hacks to work.

@jzabroski
Copy link
Collaborator

@jmevel I was unaware of this feature request since helping Ivan, since the original requestor closed it. Its a hard problem to deal with when people are frustrated about things out of my hands (not aware of pain point). And then, rather than opening a new issue, people post on the Closed issue expecting people will see it.

As far as making this work, I don't see why it would be impossible.

@jmevel
Copy link

jmevel commented May 19, 2020

@jzabroski people comment on closed issues because they can still be re-opened.

If you want tickets to be re-created then fine I'll do that for another one which was closed by Ivan but in my opinion this action wasn't justified.

@jmevel
Copy link

jmevel commented May 19, 2020

@jzabroski Actually even after re-reading the comments I wouldn't be able to open a new ticket and simply explain the problem. I haven't used RazorLight for a while.

But you should definitely read what I wrote some time ago on this ticket.
I never managed to get RazorLight working completely with string templates

@jzabroski
Copy link
Collaborator

@jmevel I'm sorry for your paint points - I don't use string templates, but it does seem like that is the one area users complain most about. Recent PRs from others have sought to address some holes, and it has overall improved the code base a bit.

I get why people comment on old issues, but I think there is some "netiquette" around bumping issues closed >3 years ago.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants