Copied to clipboard

Flag this post as spam?

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


  • BartKrul 8 posts 88 karma points
    Jan 05, 2017 @ 16:14
    BartKrul
    0

    Acces to GetPropertyValue and having a ViewModel?

    Hi,

    I have this page where information is loaded from umbraco with IPublishedContent:

    @{
    List<ContentBlok> blokken = new List<ContentBlok>();
    var items = Model.GetPropertyValue<IEnumerable<IPublishedContent>>("blokken");
    foreach (var item in items)
    {
        var blokTitel = item.GetPropertyValue("titel") != null ? item.GetPropertyValue("titel") : "";
        var iscounterblock = item.GetPropertyValue("Verzoeken") != null ? item.GetPropertyValue("Verzoeken") : false;
        var isimportant = item.GetPropertyValue("Belangrijk") != null ? item.GetPropertyValue("Belangrijk") : false;
        var content = item.GetPropertyValue("Content") != null ? item.GetPropertyValue("Content") : new HtmlString("a");
        ContentBlok blok = new ContentBlok
        {
            IsCounterBlock = (bool)iscounterblock,
            IsImportant = (bool)isimportant,
            Content = (HtmlString)content,
            Titel = (string)blokTitel
        };
        blokken.Add(blok);
    }
    
    <div class="o-grid  js-grid">
        @foreach (var item in blokken)
        {
            @Html.Partial("PartialContentBlock", item);
        }
    </div>
    

    But when I add an @model tag to the view I cannot access GetPropertyValue and the umbraco items anymore.

     public ActionResult Index()
        {
            JavaScriptSerializer serializer = new JavaScriptSerializer();
            User user = (User)serializer.Deserialize
            (((FormsIdentity)System.Web.HttpContext.Current.User.Identity)
            .Ticket.UserData,
            typeof(User));
    
            HomeViewModel homeViewModel = new HomeViewModel
            {
                ShowPortaal = user.ShowPortaal,
                AllPerms = user.AllPerms
            };
                return View("Home", homeViewModel);
        }
    

    Is there a way to get both?

  • BartKrul 8 posts 88 karma points
    Jan 06, 2017 @ 13:10
    BartKrul
    0

    Solved with extending the Model with RenderModel.

Please Sign in or register to post replies

Write your reply to:

Draft