Closed mika76 closed 2 years ago
It doesn’t. Razor is too tied with MVC to be separated out. We did have a plug-in to work with handlebars which stalled but would be happy for someone to give it a go
On Sat, 7 Mar 2020 at 08:40, Mladen Mihajlović notifications@github.com wrote:
I see there is a carter mvc sample but it's missing the V part - does Carter provide some sort of View engine (I see nothing mentioned in the repo or in the issues), if not is it planned? if so could you provide a sample?
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/CarterCommunity/Carter/issues/242?email_source=notifications&email_token=AAAZVJX7FOXNVJMOSB7RB33RGIB6JA5CNFSM4LDNWOH2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4ITI5VAQ, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAZVJROID2KNRLHF7GCCULRGIB6JANCNFSM4LDNWOHQ .
Interesting I see Nancy uses this one https://github.com/grumpydev/SuperSimpleViewEngine
I see there is a carter mvc sample but it's missing the V part - does Carter provide some sort of View engine (I see nothing mentioned in the repo or in the issues), if not is it planned? if so could you provide a sample?
Two options that work reliably.
The plugin I mention above is here https://github.com/CarterCommunity/Carter.HtmlNegotiator/blob/master/src/HtmlNegotiator.cs
I've been experimenting a bit more with MVC controllers and found out you can use the controllers just for the views, as long as you don't use the same route twice, such as /view in a controller and /view in a module. What works fine is /view for controller and Get/Post("/view/xyz") in the module. I'm now using a controller just to serve the views. All json stuff is done by the modules. The upside is that this is much faster than using RazorLight (response times are less than 20% of the time with RazorLight).
If you'd like to send a PR to amend the CarterAndMVC sample we have, I'd love to see that - https://github.com/CarterCommunity/Carter/tree/master/samples/CarterAndMVC
With a few small adjustments (due to some breaking naming changes in .NET Core 3) you can make the HTML Negotiator work (mentioned earlier) with the latest release.
I also found https://github.com/lunet-io/scriban which is a text templating engine which might be able to work...
@DirkJanIT , do you have any example code using Razor? We have a large Nancy application that we are looking to migrate over, but its view are all Razor-based.
I'm also using Carter with built-in Razor. You'll basically need to add the standard MVC code to Startup (https://github.com/CarterCommunity/Carter/blob/master/samples/CarterAndMVC/Startup.cs), for example: https://gist.github.com/PhyxionNL/61cedf66cf704f55eff985ceac0c0199
This way you can use controllers for views and modules for the rest (json/xml/whatever you'd like to serve). You obviously cannot use the same route twice, so you need to keep track of which routes are used. It's probably possible to return a view from a carter module with a bit of code, but I just use a controller for serving the views.
I see there is a carter mvc sample but it's missing the V part - does Carter provide some sort of View engine (I see nothing mentioned in the repo or in the issues), if not is it planned? if so could you provide a sample?