Copied to clipboard

Flag this post as spam?

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


  • FarmFreshCode 225 posts 422 karma points
    Jun 13, 2011 @ 22:30
    FarmFreshCode
    0

    Output Checkbox values in Razor

    Hello Everyone, thanks for your help in advance. This should be a simple one but I haven't gotten it to work yet. p.s. I am using Umbraco 4.7

    I have a Member Type Checkbox list with the alias (facultyDepartments) where my members can check off all of the departments that they are involved in. What I want is to have the values displayed on my website like this: "Department A, Department B, Department C" but what I keep outputting is "88, 89, 92" <-- The id numbers for the checkbox items.

    <umbraco:Macro runat="server" language="cshtml">  
    @using umbraco.cms.businesslogic.member

      @{
        var memberId= HttpContext.Current.Request.QueryString["id"];
      }

        @if(memberId != null) {
          <!-- THIS IS THE VALUE THAT NEEDS HELP -->
    var departments = member.getProperty("facultyDepartments").Value.ToString();

        <div id="detail">@departments</div>
      }  
       


    else { 

        <!-- THUMBNAIL DISPLAY -->
        <!-- THIS SECTION WORKS GREAT -->
        var members = Member.GetAll;   
        foreach(var item in members){
          var buildingLocation = item.getProperty("facultyBuildingLocation").Value.ToString();
          var roomNumber = item.getProperty("facultyRoomNumber").Value.ToString();
          var facultyCV = item.getProperty("facultyCV").Value.ToString();
     
          <!-- THIS ONE WORKS BUT IS USING item.getProperty -->
    @{
      var departments = item.getProperty("facultyDepartments").Value.ToString();
      foreach(var id in departments.Split(',')) {
       var memberDepartments = umbraco.library.GetPreValueAsString(Convert.ToInt32(id));
        <li>@memberDepartments,&nbsp;</li>
      }
    }

    You can see comments in my code that mention the "Thumbnail Display" everything below that works just fine.. but this second area of code is using item.getProperty instead of member.getProperty like the first one is.

    How can I get the values of my checkbox list in that first section??

    THANK YOU!

  • Richard Boelen 61 posts 153 karma points
    Jun 14, 2011 @ 12:52
    Richard Boelen
    0

    Hi,

     

    I'm not sure but can you try this:

     
    <umbraco:Macro runat="server" language="cshtml">  
    @using umbraco.cms.businesslogic.member
      @{
        var memberId= HttpContext.Current.Request.QueryString["id"];
      }
     
        @if(memberId != null) {
           <!-- THIS IS THE VALUE THAT NEEDS HELP -->
           var member = new Member(Convert.ToInt32(memberId));
           var departments = member.getProperty("facultyDepartments").Value.ToString();
     
           <div id="detail">
           @foreach(var id in departments.Split(',')) {
    var memberDepartments = umbraco.library.GetPreValueAsString(Convert.ToInt32(id));
    @memberDepartments, 
           }
           </div>
      }  
        
    else {  
        <!-- THUMBNAIL DISPLAY -->
        <!-- THIS SECTION WORKS GREAT -->
        var members = Member.GetAll;    
        foreach(var item in members){
          var buildingLocation = item.getProperty("facultyBuildingLocation").Value.ToString();
          var roomNumber = item.getProperty("facultyRoomNumber").Value.ToString();
          var facultyCV = item.getProperty("facultyCV").Value.ToString();
      
           <!-- THIS ONE WORKS BUT IS USING item.getProperty -->
    @{
      var departments = item.getProperty("facultyDepartments").Value.ToString();
      foreach(var id in departments.Split(',')) {
       var memberDepartments = umbraco.library.GetPreValueAsString(Convert.ToInt32(id));
        <li>@memberDepartments, </li>
      }
    }

    Cheers,
    Richard

  • Richard Boelen 61 posts 153 karma points
    Jun 14, 2011 @ 12:54
    Richard Boelen
    0

    What's wrong with de code formatting???

Please Sign in or register to post replies

Write your reply to:

Draft