Copied to clipboard

Flag this post as spam?

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


  • Nikola Romcevic 26 posts 139 karma points
    Nov 20, 2013 @ 15:05
    Nikola Romcevic
    0

    Can't use Umbraco.Content

    Sorry for the arbitrary headline but I lack the correct umbraco terminology.

    The problem:

    I'm using a PartialView that looks like the following:

    @model IEnumerable<CartItemModel>
    
    <table class="checkout-products">
        ...
        @foreach(item in @Model){
            <tr class='product' data-pid='@item.ProductId'>
                <td>@item.Name</td>
                <td>@item.Quantity</td>
                <td>@item.Price</td>
            </tr>
        }
        ...
    </table>
    

    So, what I want to add to this is a var p = Umbraco.Content(item.ProductId) in the beginning of the foreach-loop for various reasons. But when I try to do this I get an CS0234: The type or namespace name Content does not exist in the namespace Umbraco-error.

    What am I missing?

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Nov 20, 2013 @ 15:09
    Jeavon Leopold
    101

    Hi Nikola,

    You need to inherit from Umbraco.Web.Mvc.UmbracoViewPage, e.g. @inherits Umbraco.Web.Mvc.UmbracoViewPage<IEnumerable<CartItemModel>>

    More information here

    Jeavon

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Nov 20, 2013 @ 15:12
    Dennis Aaen
    1

    HI Nikola,

    I havenĀ“t worked with PartialView yet, but I know from my working with Razor i macroScript, the Razor engine wil throw an error if you have an @ in front of Model in the foreach loop.

    So you could try to remove it an see if it solve your problem.

    @modelIEnumerable<CartItemModel>

    <table class="checkout-products">
       
    ...
       
    @foreach(item in Model){
           
    <tr class='product' data-pid='@item.ProductId'>
               
    <td>@item.Name</td>
                <td>@item.Quantity</
    td>
               
    <td>@item.Price</td>
            </
    tr>
       
    }
       
    ...
    </table>

    /Dennis

  • Nikola Romcevic 26 posts 139 karma points
    Nov 20, 2013 @ 15:19
    Nikola Romcevic
    0

    Thank you Jeavon, that did the trick!

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Nov 20, 2013 @ 15:28
    Jeavon Leopold
    0

    Perfect!

Please Sign in or register to post replies

Write your reply to:

Draft