Skip to content

Instantly share code, notes, and snippets.

@rasmusfjord
Created July 6, 2015 09:14
Show Gist options
  • Select an option

  • Save rasmusfjord/070558245ae4ef91ec11 to your computer and use it in GitHub Desktop.

Select an option

Save rasmusfjord/070558245ae4ef91ec11 to your computer and use it in GitHub Desktop.
@inherits Umbraco.Web.Mvc.UmbracoViewPage<Umbraco.Core.Models.IPublishedContent>
<p>@Umbraco.GetDictionaryValue("Værelse")</p>
public class BookingController : SurfaceController
{
public ActionResult GetRoomMarkup(int id)
{
return PartialView("booking-rooms", Umbraco.TypedContent(id));
}
}
@ismailmayat
Copy link

Ignore the servicefactory and getculturecode bit you need to pass in the culture code you could get that from current node or its home page?

@rasmusfjord
Copy link
Author

Arh roger got it ! :D

@rasmusfjord
Copy link
Author

My solution ended up being like this :
View:

@Url.Action("GetRoomMarkup", "Booking", new { id = CurrentPage.Id, lang= Model.Content.GetCulture() })

Surfacecontroller Inheriter:

 public class AjaxSurfaceController : SurfaceController
    {
        protected void SetCultureForAjax(string lang)
        {
            //Get the culture info of the language code
            CultureInfo culture = CultureInfo.CreateSpecificCulture(lang);
            Thread.CurrentThread.CurrentCulture = culture;
            Thread.CurrentThread.CurrentUICulture = culture;
        }
    }

Surfacecontroller that inherites:

 public class BookingController : AjaxSurfaceController
    {

        public ActionResult GetRoomMarkup(int id, string lang)
        {
            if (ControllerContext.HttpContext.Request.IsAjaxRequest())
            {
                SetCultureForAjax(lang);
            }
            return PartialView("booking-rooms", Umbraco.TypedContent(id));
        }

    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment