9

First I need to say that my experience with Asp.net is very small, that's why this question could come of confusing in some parts. I've first created https://code.visualstudio.com/Docs/ASPnet5 a MVC6 project via yo aspnet. Then I've added this line to "dependencies" in project.json

"Microsoft.Framework.ConfigurationModel.Xml": "1.0.0-beta4",
"System.Web.NHaml.Mvc3": "4.0.8",

Then I've created haml.xml with this Google code content and extended the following line in the Startup.cs file:

var configuration = new Configuration()
            .AddJsonFile("config.json")
            .AddXmlFile("haml.xml")
            .AddJsonFile($"config.{env.EnvironmentName}.json", optional: true);

this is how my controller looks like:

public class HomeController : Controller
{
    public IActionResult Index()
    {
        return View(@"~/Views/Shared/Test.haml");
    }
}

the apps starts up, but I can't render the action, this is the error that shows up in the browser

An unhandled exception occurred while processing the request.

InvalidOperationException: The view '~/Views/Shared/Test.haml' was not found. The following locations were searched: ~/Views/Shared/Test.haml. Microsoft.AspNet.Mvc.Rendering.ViewEngineResult.EnsureSuccessful () [0x00000] in , line 0

But this file does exist in this directory. Any hints or help is appreciated.


BOUNTY edit:

Basicly what I want is a detailed explanation or a working example of a very very simple MVC 5 or 6 Project that uses NHaml or any other lib that Provides Haml syntax (If it works with Mono on osx, that's a bonus). Tanks a lot!

Community
  • 1
  • 1
antpaw
  • 15,444
  • 11
  • 59
  • 88
  • http://stackoverflow.com/questions/24126053/how-to-use-nhaml-in-mvc-4 – Onur Topal Jun 23 '15 at 15:21
  • It's mvc 4, and I followed the instruction but couldn't do it because I don't know where and how `ViewEngines.Engines` is available in mvc 5 or 6. – antpaw Jun 23 '15 at 17:24
  • The NHaml wiki link is from 2009. We are talking about ancient version of the MVC Framework. Begin by undoing everything applied there. – Dave Alperovich Jun 23 '15 at 17:35
  • 6
    The last edition of NHaml View Engine was published Jan 2013. Had less than 500 downloads all time. https://www.nuget.org/packages/System.Web.NHaml.Mvc3/ The View Engine never caught on, Razor is the predominant in use. MVC 6 has been configured to use whatever View Engine you want, but are 99% likely the first one to try it with MVC 6. As Asp.Net 5 is still RC, I doubt Microsoft has even added support for this. You would have to implement it yourself. – Dave Alperovich Jun 23 '15 at 17:53

3 Answers3

3

I was wondering to say this there is no support from Haml for MVC5 AND MVC 6

beacause The Haml View Engine Project maybe discontinued. the last commit appeared in Feb 25, 2013.. Also HAML view engine issues are not resolved today itself.The last realease of Haml View engine in nuget at 2013 Feb.So this not make sense.

So instead you Use Spark View engine its support Mono also..

Also spark have support "left-offset" syntax inspired by frameworks like Jade and Haml

The project documentation is here

you also install the binaries from Nuget

Also spark provide samples for configure view engines.

Good Luck...

Happy coding.

Jagadeesh Govindaraj
  • 6,977
  • 6
  • 32
  • 52
1

I think it is the Razor view engine throwing that error.

As of getting an NHaml view engine with asp.net 5 MVC6 I could not manage to get that working since it would require me to rewrite it to inherit from IViewEngine. This is the error I think you should have received if you try with a debugger enabled Visual Studio code editor. Could you try Visual Studio 2013 Community or VS 2015 Trial version to see if you get the following error? enter image description here

This is where your current ViewEngine fails right now giving the impression of a missing file. Source code for OP provided error message Does it work if you change your haml file to a cshtml file?

Magnus Karlsson
  • 3,549
  • 3
  • 31
  • 57
  • hey, yes it works if i change haml to cshtml but then i have to use razor syntax. I've tried to add the ViewEngie via code too, but i was stuck at this exception. Do you know how to solve the ArgmentException? – antpaw Jun 29 '15 at 13:46
  • @antpaw The only way to solve it is to use an old version of asp.net mvc or rewrite NHaml. Here is a link to NHaml repo on Github. https://github.com/NHaml/NHaml/tree/master/src/System.Web.NHaml You have to rewrite it to inherit from IViewEngine. – Magnus Karlsson Jun 29 '15 at 15:36
  • @antpaw By the way, I used to do Ruby stuff and I dont think you get disappointed going with Razor. There is a reason no one keeps an alternate view engine up to date. Best of luck to you! – Magnus Karlsson Jun 29 '15 at 15:39
  • @antpaw Was I not clear stating NHaml don't support MVC5 or 6? I think I should have received the correct answer for this question. – Magnus Karlsson Jun 30 '15 at 16:46
0

There is another alternative, but for ASP.NET Core. See below from the github site https://github.com/AspNetMonsters/pugzor

Pugor is the Pug view engine for ASP.NET Core. You might know pug by its previous name, Jade. You can read more about Pug over at their website: https://pugjs.org/api/getting-started.html

Pugzor works by passing your models directly to the node version of pug via Steve Sanderson's glorious JavaScript services. It is actually pretty performant and there are many optimizations still to be made.