Copied to clipboard

Flag this post as spam?

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


  • Berto 105 posts 177 karma points
    Jan 31, 2013 @ 17:21
    Berto
    0

    Umbraco 6 MVC Alternate Templates

    Hi,

    I fooling around with Umbraco 6 and mvc, and I'm having trouble to make an alternate template. Is this possible with mvc umbraco?

    And another question, Is it possible to Create a controller that returns the content in json?

    Thx

    Berto

  • Berto 105 posts 177 karma points
    Feb 05, 2013 @ 11:00
    Berto
    0

    Aynone?

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Feb 05, 2013 @ 12:13
    Jeroen Breuer
    0

    Alt templates should work, but there are exceptions: http://our.umbraco.org/forum/using/ui-questions/37937-What-shall-we-do-with-AltTemplate

    You can create a surface controller and let that return json:

    Here's a quick example:

    public class JsonController : SurfaceController
    {
        [HttpPost]
        public ActionResult UpdateVariantAmount(int variantId, string amount)
        {
            //do stuff
    
            return Json("");
        }
    }
    $(".quotationAmount").keyup(function () {
    
        var variantId = $(this).closest("form").find("input[type=hidden]").val();
        var amount = $(this).val();
    
        $.ajax({
            url: '/umbraco/Surface/Json/UpdateVariantAmount',
            type: 'POST',
            dataType: 'json',
            data: '{ "variantId": ' + variantId + ', "amount": "' + amount + '" }',
            contentType: 'application/json; charset=utf-8',
            success: function (data) {
                //do stuff
            }
        });
    
    });

    Don't forget to add the url to umbracoReservedUrls in the web.config: ,~/umbraco/Surface/Json/UpdateVariantAmount

    Jeroen

  • Berto 105 posts 177 karma points
    Feb 05, 2013 @ 12:29
    Berto
    0

    Hi Jeroen,

    From my experiences, alt templates aren't working, but I will confirm it.

    I think that i was trying to do was to have a controller that returnet the content in json, something on the likes of this:

    http://www.umbraco6.com/mysuperpage --> Returns an html page

    http://www.umbraco6.com/mysuperpage/json -->Returns the data of that page in Json

    Is this possible?

     

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Feb 05, 2013 @ 12:43
    Jeroen Breuer
    0

    It should if you add some custom routing: http://our.umbraco.org/documentation/Reference/Mvc/custom-routes

    Jeroen

  • Berto 105 posts 177 karma points
    Feb 05, 2013 @ 12:50
    Berto
    0

    Hmmm... Ok, I have to try it ;)

    Thx for the help, I will give feedback :D

    Berto

  • Edwin van Koppen 156 posts 270 karma points
    Feb 05, 2013 @ 13:00
    Edwin van Koppen
    0

    What Jeroen said!

  • Mohamed Rafeeq 6 posts 26 karma points
    Feb 07, 2013 @ 12:26
    Mohamed Rafeeq
    0

    Do we need to use MVCBridge in Umbraco 6 to add the view/controller in the template??

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Feb 07, 2013 @ 12:39
    Jeroen Breuer
    1

    No. Just do what it says here and it should work :-). http://our.umbraco.org/documentation/reference/mvc/custom-controllers

    Jeroen

  • Mohamed Rafeeq 6 posts 26 karma points
    Feb 07, 2013 @ 13:31
    Mohamed Rafeeq
    0

    Thanks Joroen, Its awesome.. I guess if I want to add it as a partial view, I need to do the same as we do in MVC.

    I was cofused the way we adding macros and mvc view in the template, looks both have different ways now..!!

Please Sign in or register to post replies

Write your reply to:

Draft