Copied to clipboard

Flag this post as spam?

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


  • Libin Joseph 9 posts 31 karma points
    Sep 30, 2013 @ 08:22
    Libin Joseph
    0

    Bind values to dropdown list using razor syntax

    My Development Enviorment

    Using Umbraco : Version 6.1.5

    MVC with Razor

    And it have also made the necessary changes in config file for the MVC.

    Steps that I followed

    Step 1
    I went to the developer section and added a custom datatypes called "cleaningtypes" with the property editor set to "Multiple Textstring".
     
    Step 2

    I then went into Document Types and then added a new Document Type named "cleaning" and then went on to create a property named "text" with type set as "cleaningtypes"

    Step 3

    I then went into Content and then added had some values into the fields that I have created.

    Step 4

    Under the Templates section I went to the "cleaning" template added the following code to check if would receive the values that I just added.
     @Umbraco.Field("text")

    Step 5

    And it works as I expected. I get all the values that I inserted.

    Step 6

    Now I wanted to bind these values into a dropdown list. So i edited the code with the following statments.
    <select>
     @foreach (var item in Model.text){
     <option>@item.InnerText</option>
    }
    </select>

    Step 7

    And when I run the website, I get an error.
    I look forward for your valuable help and suggestions.
  • Jeavon Leopold 3008 posts 13221 karma points MVP 7x admin c-trib
    Sep 30, 2013 @ 09:11
    Jeavon Leopold
    0

    Hi Libin, I think you have posted the perfect description!

    I think you only need to change your foreach to:

    @foreach (var item in CurrentPage.text){
    

    Jeavon

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies