Copied to clipboard

Flag this post as spam?

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


  • Martin 114 posts 313 karma points
    Nov 10, 2015 @ 19:27
    Martin
    0

    Passing Umbraco.Field to partial view

    Hi,

    I have a problem passing the pageName to a partial view. It works fine if I use a static city for OrtName e.g.

    {"Ort", "Stockholm"}

    but I have no success in passing Umbraco.Field("pageName") as OrtName. How could this be done?

    Hope for help /martin

    ,

    @{
        var OrtName= Umbraco.Field("pageName");
        Html.RenderPartial(
            "ListaLediga",
            Model.Content,
            new ViewDataDictionary(this.ViewData) {
                { "Ort", @OrtName},
                { "dummy", true }
            }
        );
    }
    
  • Tim Miller 32 posts 252 karma points
    Nov 10, 2015 @ 22:50
    Tim Miller
    0

    Your code seems to work fine for me, which leads me to believe the problem may be how you're using the variable in your partial. Can you post some of that code? I did this in the partial and it worked fine:

    <h1>@ViewData["Ort"]</h1>
    
  • Tim Miller 32 posts 252 karma points
    Nov 10, 2015 @ 22:54
    Tim Miller
    100

    Your code seems to work fine for me, which leads me to believe the problem may be how you're using the variable in your partial. Can you post some of that code? I did this in the partial and it worked fine:

    <h1>@ViewData["Ort"]</h1>
    

    If I had to guess, you may be expecting a string and may need a .ToString().

  • Martin 114 posts 313 karma points
    Nov 11, 2015 @ 10:24
    Martin
    0

    Hi five Tim!

    OrtNamn.ToString() solved it!

    Thanks alot!

Please Sign in or register to post replies

Write your reply to:

Draft