Open DMW007 opened 8 years ago
Hi there
As mentioned here #16 - taghelpers and UrlHelpers are not implemented. I am going to roll up a stable version soon, and more likely it will not be implemented there, as we are on Release Candidate now. I will add this to backlog, but expect this on the next major release.
In your case you can write pure HTML for building links for now, it's not critical, but yes, a lot of people were asking where are tag and url helpers, so it has to be added.
Thanks, stay tuned
How would we go about using Html.Raw()? I believe this is impacted.
@kudoz83 You can use @Raw in order to workaround Html.Raw(), which basically the same function but outside of HtmlHelper implemented as Razor page function
What do I need to import to get that method
@kudoz83 Nothing :) It's already there, give it a try
Sorry if I'm just dense, but I I don't have @Raw as an option in my cshtml file. I assume I need a using or inject?
@kudoz83 The thing is that your Visual Studio has Intelisense that uses built-in Razor engine tooling, and it has no @Raw method. Visual Studio knows nothing about RazorLight and therefore - nothing about it's functions. So yea, you might not get appropriate hints from IDE, that's the thing, but just try to write @Raw and use RazorLight to compile your view. It should work. Let me know if it didn't :)
Ok it works. Sorry for the confusion.
Doesn't seem you can actually build a project when the views contain @Raw()
- is there a workaround?
Can you show what error you are getting? That would help a lot
The name Raw does not exist in the current context.
I understand that RazorLight will compile the template, but visual studio checks the CSHTML on build and shits itself.
I guess changing extension from *.cshtml to something might solve the problem
In a netcore project:
"buildOptions": {
"emitEntryPoint": true,
"preserveCompilationContext": true,
"compile": {
"exclude": [
"**/*.cshtml",
"node_modules"
]
}
},
This will allow you to compile/publish but will not remove the errors from the output window. Ideally Razorlight should expose all of it's helpers for import into views.
I found a better workaround.
@{ var rawString = new RazorLight.Text.RawString(content); }
...
Here I want to print @(rawString) without any compile issues.
I think it would make sense to create a RazorLight static that can be injected with these helper functions, rather than just say "oh well."
Not quite sure what do you mean on "just say 'oh well'", as there is an existing solution to write Raw string, and I tried my best to explain it to you.
If you have better solution - I'm open for pull requests, and I will do appreciate your contribution
Any news about support for taghelpers and UrlHelpers? Missing support is a showstopper for me.
ditto: Any news about support for taghelpers and UrlHelpers? Missing support is a showstopper for me. And HtmlHelpers?
This will be implemented as a part of RazorLight 2.0 that will start it's development at the moment .NET Core 2.0 will be released
Hi @toddams Any update for this feature?
Looking forward to see @Html.Partial support too. There is just no way to do this @ the moment...
Include != Html.Partial. I would like to see support for all Html.* calls, just like they work in 'normal' views. The reason being that I do not want to modify an existing project - over 1500 views... Any idea on how to achieve this, is more than welcome!
Can u tell the the difference between Html.Partial and Include, except name? Maybe I'm missing the point
The difference is syntax, so you are not missing any point. It may be functionally identical, but I need the Html helpers to work... If there is a way to get the normal Html.* helpers working in RazorLight, this would open some other possibilities as well, like minifying the views before they are compiled. That is what I am looking for.
Which is the supported tags overview right now?
Which is the supported tags overview right now?
don't work.
Badly missing functionality. I have to duplicate lots of views only because of this :( Anyway, big plus to the contributors for their good work on this promising package!
Still missing for years. I realize this is a free and open source project, but if anyone can give guidance on how to add html helpers to this project so that views work as they do in a vs project I'd be happy to do the work.
any news on adding this feature?? tag helper is base feature of razor views in asp.net core this is very useful
I was hoping to use these tag helpers for our emails so we don't need to write html like its the 90's. https://github.com/XmlmXmlmX/InkyTagHelpers
I think we should close this ticket and open a new one with a clear list of what needs to be done.
Off the top of my head, the core features are managing scope of the TagHelper, documented here:
@addTagHelper
makes TagHelpers available@removeTagHelper
removes Tag Helpers_ViewImports.cshtml
file@tagHelperPrefix
to make Tag Helper usage explicitAs you can see from this list, some of these features are fairly complicated. The main concern would be making sure IntelliSense also still works.
Hi,
I would like to use your library for email-templates, which contains links to the application itself. Sadly, RazorLight seems to parse razor code, but not the ASP.NET Core TagHelpers. For example, the asp-controller and asp-action attribute to generate an action-controller link like this:
<a asp-controller="Account" asp-action="Login">Test</a>
Using dependency injection, a instance of
IRazorLightEngine
is injected in my constructor. There I call theParse
method like this:var html = razorEngineLight.Parse("Shared/Test.cshtml", new object());
But in the rendered html, I don't get a parsed link like
<a href="/Account/Login">Test</a>
as expected. Instead, I get 1:1 the source code with asp-controller and action attribute like showed above. So it seems that the
_ViewImports.cshtml
file in the View-folder is not globally parsed like ASP.NET Core do it. I tried to add the tag helpers manually using@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
in the Razor-View, but its not working. As a workaround, I tried to use the old UrlHelpers from ASP.NET like this way:
This is valid code, as it works in a normal Razor-View. But using RazorLight, I got a
RazorLight.TemplateCompilationException: Failed to compile generated razor view. See CompilationErrors for detailed information
. In the details, Visual Studio show me that there is one CompilationError (Cound = 1) but there seems no way to extend or otherwise view them.As a result, it seems not possible to create action-controller links using Razor, which is a problem in my point of view. Would be pleased if this could be fixed.