asp.net-mvcasp.net-mvc-4mustache

ASPNET MVC 4 and mustache


I'm writing an ASPNET MVC 4 application and I'm trying to use mustache templates. My problem is that I always get an 404 for the file and I don't realize what the problem is. Any ideas?

I'm creating a hidden control with the url in index.html like this:

@Html.Hidden("urlMustacheTemplates", Url.Content("~/Views/Templates/"))

then in a javascript file

$.get($("#urlMustacheTemplates").val() + "main.mustache", function (template) {
    var html = Mustache.to_html(template, data);
    output = $.mustache(template, data);
});

I put a

debugger;

in the javascript and I see the url is correct, my file in

/Views/Templates/main.mustache

But I get a 404 file not found.


Solution

  • Take your templates folder out of the Views Folder and put it in the root or in an Assets Folder.

    /Assets/Templates/main.mustache

    or

    /Templates/main.mustache