Copied to clipboard

Flag this post as spam?

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


  • manu 3 posts 33 karma points
    Nov 07, 2013 @ 07:32
    manu
    0

    Bind Values To DropDown From Contents

            **My Development Enviorment**
    
             Using Umbraco : Version 6.1.5
    
              MVC with Razor
    
          **Steps Followed**
    
            **step 1**
    
    
      i went to developer section and there in Package section install uComponent 
      package then create a datatype 'Text string array' property editor set to
      Ucomponent textstring Array
    

    enter image description here

      **step 2**
         I then went into Document Types and then added a new Document Type named
    
        "clean1" and then went on to create a property named "numberOfBedrooms"
         with type set as "TextstringArray"
    

    enter image description here

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

    enter image description here

      **step4**
    
    Then i created a partial view named ContactUs to bind the values from the
    contents to a drop down list for that i take the parent id below is ma
    particlar section code..
    
    
    
    <div class="select">
    
             <select id="Bathrooms" >
    
        @{
    
            var newnode = Umbraco.Content(1310);  
    
        foreach(var item in newnode.Children().Where("Visible"))
        {
    
            var count = 0;
            foreach (var counter in item.numberOfBedrooms)
            {
             count = count + 1;
            }
    
    
            for (int i = 0; i < count; i++){
                foreach (var qLoop in item.numberOfBedrooms[i]){
                    <option>@qLoop.InnerText</option>
    
                }
            }
        }
                            }
    
    
                            </select>
                        </div>
    
          **step5**
     But while running i hv geting the following error  
    

    enter image description here

    at the header i added 
           @model MvcApplication2.Models.ContactUs
    @using umbraco.MacroEngines;
              @using umbraco.NodeFactory;
     As iam new to umbraco i look forward to your valueble comments..
    
  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Nov 07, 2013 @ 13:58
    Jeavon Leopold
    0

    Hi Manu,

    Welcome to Our!

    Try something like this:

    @inherits Umbraco.Web.Mvc.UmbracoViewPage<MvcApplication2.Models.ContactUs>
    @{
        var newnode = Umbraco.Content(1310);
    
        foreach (var item in newnode.Children.Where("Visible"))
        {
            foreach (string[] row in item.numberOfBedrooms)
            {
                <li>
                    @row[0] @row[1]
                </li>
            }
        }
    }
    

    Jeavon

  • manu 3 posts 33 karma points
    Nov 08, 2013 @ 06:21
    manu
    0
       hai jeavon,
    
         Thankx For the reply but when i run this code i get the following Error
    

    enter image description here

      Then i tried out a similar code in macro 
    

    enter image description here

    when i render the macro it shows no errors but the value from the contents is not binding
    
  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Nov 08, 2013 @ 07:51
    Jeavon Leopold
    0

    Ah of course, you will need uComponents v6 for this to work

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Nov 08, 2013 @ 07:56
    Jeavon Leopold
    0

    This code is not be used as Scripting File macro, it should be used as a Partial View. You should not use Scripting files at all when using MVC, they are legacy.

    When using MVC, you should use Partial Views mostly, if you really need a macro for use in a RTE for example, then you can use a Macro Partial View, more in of on this here

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Nov 08, 2013 @ 08:01
    Jeavon Leopold
    100

    Without uComponents v6, I think something like this might work

    @inherits Umbraco.Web.Mvc.UmbracoViewPage<MvcApplication2.Models.ContactUs>
    @{
        var newnode = Umbraco.Content(1310);
    
        foreach (var item in newnode.Children.Where("Visible"))
        {
     <table>
        @foreach (var row in item.numberOfBedrooms)
        {
            <tr>         
                @foreach (var cell in row)  
                {   
                    <td>@cell.InnerText</td>
                }
            </tr>
        }
    </table> 
    
        }
    }
    
  • manu 3 posts 33 karma points
    Nov 08, 2013 @ 08:01
    manu
    0
        @jeavon:haii Thankx alot code worked...now a little bit confution..actually iam having...one more contents which
          contain same same namespace.."number of bed rooms".
    

    enter image description here

     here the second one "clean2" it also have same details like number of bedrooms...but values changes..so my dobut is
    
     how i can display "clean2" details[with in same dropdown of clean1] when i select it...
    
  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Nov 09, 2013 @ 23:54
    Jeavon Leopold
    0

    I think it is going to do that already as it is looping through all children of node 1310 which I guess is "CleanType" in your screens shot, so just adjust the markup so that each final out is an

Please Sign in or register to post replies

Write your reply to:

Draft