Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Jan van Helvoort 15 posts 71 karma points
    Aug 18, 2014 @ 20:15
    Jan van Helvoort
    0

    Direct load .cshtml

    Hi everyone,

    Is it possible to load a cshtml template? I have a template, contacs.cshtml, plain html. with: http://localhost/Views/contacs.cshtml i get a 404 (Server Error in '/' Application. / The resource cannot be found.).

    i have set the follow things in the views/web.config:

    <modules runAllManagedModulesForAllRequests="true" />
    <add key="webpages:Enabled" value="true" />
    

    with kind regards

    Jan.

    Edit: a work around, not desirable

    public class ViewsController : SurfaceController
    {
        public ActionResult Index(string alias)
        {
            return View("~/Views/" + alias + ".cshtml");
        }
    }
    

    http://localhost/umbraco/surface/views/index?alias=contacs

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Aug 18, 2014 @ 23:23
    Sebastiaan Janssen
    0

    Well http://localhost/contacts should work.

    Any template that's been created in Umbraco can be appended to any url. http://localhost/contacts means: load the homepage with the contacts template instead of the saved template.

    See:
    http://umbraco.tv/videos/umbraco-v7/implementor/fundamentals/templating/alt-template/documentation
    http://www.nibble.be/?p=42

  • Jan van Helvoort 15 posts 71 karma points
    Aug 19, 2014 @ 09:28
    Jan van Helvoort
    0

    Thank you,

    But I want load the content of the template, for example inside a div.

    I have chosen for templates, so I can change the content through Umbraco.

    Jan.

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Aug 19, 2014 @ 10:13
    Sebastiaan Janssen
    0

    Alright, no problem. It's best to put them in the Views/Partials folder but they can live anywhere you want, call the view using:

    @Html.Partial("~/Views/Partials/Contacts.cshtml", Model)
    

    I think the partial view needs to start with @inherits UmbracoTemplatePage as the first line but I'm not entirely sure, but that's easy to test.

  • Jan van Helvoort 15 posts 71 karma points
    Aug 19, 2014 @ 20:12
    Jan van Helvoort
    0

    Not really what I was hoping for, the templates are plain html, no razor. What if i want them to load with jquery: $("#contact").load("http://localhost/views/contact.cshtml");

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Aug 19, 2014 @ 20:28
    Sebastiaan Janssen
    0

    That's just not how Razor works.. If you want to load them with jQuery you could do something like this I guess: http://stackoverflow.com/questions/9958282/how-do-i-load-html-into-a-variable-with-jquery

    So the question really is: is that ultimately what you want to do or is it just an example. If you describe what you really in the end want to do it's much easier to help. :)

  • Jan van Helvoort 15 posts 71 karma points
    Aug 19, 2014 @ 20:35
    Jan van Helvoort
    0

    Can i send you a mail in dutch, my english is not that good for a long answer

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Aug 19, 2014 @ 20:37
    Sebastiaan Janssen
    0

    I live in Denmark!

    Sorry, but please keep it on the forum, I might not have time to answer in the next few days (very likely) and in that time someone else could help you instead.

  • Jan van Helvoort 15 posts 71 karma points
    Aug 19, 2014 @ 20:59
    Jan van Helvoort
    0

    I want a template link to a document type.

    With the Umbraco Api I want to retrieve all document types that ends with a given alias.

    Here, the back end user can select with a custom property editor the document types that contains the alias. After that, I want to render every document types default template. witch can be everything, plain html, html with angular.

    In the newly rendered template, i will render a next template, witch can be every allowed child's document type default template.

    These templates are not used by Umbraco self, they only live there so i can link the template to a document type.

    I want do this in the back-end of Umbraco 7+ with angular, so i can't use razor:

    @Html.Partial("~/Views/Partials/Contacts.cshtml", Model)
    

    In other words, i need to link a .(cs)html file to a document type.

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Aug 21, 2014 @ 17:55
    Sebastiaan Janssen
    0

    It's pretty hard to understand what you're trying to do and most of all why.

    So.. you want and overview of pages with specific doctype in the backoffice of Umbraco, right? Not all of them, the editor selects the ones they want. And then you want to render the documents that they picked (still in the backoffice) with their chosen template?

    It sounds like you're building some kind of live-editing option, so your editor see the page as it will look on the frontend and can change certain parts of it?

    I don't exactly get the purpose of rendering every child template.
    Also why are you using cshtml files if you do not want to do razor? Wouldn't it be easier just to use html files and load them in, with ngInclude for example?

    So let's forget about Umbraco for a minute: what's the purpose of all this, what do you want your editors to be able to do?
    As with most things on this forum; it's easier to ask "how can I do X in Umbraco" than to make all kinds of assumptions about Umbraco and try to cobble it together yourself.

  • Jan van Helvoort 15 posts 71 karma points
    Aug 21, 2014 @ 22:16
    Jan van Helvoort
    0

    It sounds like you're building some kind of live-editing option, so your editor see the page as it will look on the frontend and can change certain parts of it?

    yes, that's what I want

    I don't exactly get the purpose of rendering every child template. Also why are you using cshtml files if you do not want to do razor? Wouldn't it be easier just to use html files and load them in, with ngInclude for example?

    yes, that's what I want and have in mind

    But now I'm looking for a way to link one or more.(cs)html files to a specific document types.

    I went to use templates because they are link well to a document type.

Please Sign in or register to post replies

Write your reply to:

Draft