Copied to clipboard

Flag this post as spam?

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


  • Meni 281 posts 539 karma points
    May 05, 2013 @ 13:34
    Meni
    0

    How to retrieve checked value in checkbox property with Razor?

    Hello again.

    I have a Checkbox list data type which I created it in order to manage and control the categories in my magazine. I want to use it to my archieve pages. So each page I create I check for him the right category - gadgets / photography / etc

    My question is: when I want to display the archieve pages - how can I retrieve the checked value from the Checkbox property?

    This is actually what I'd like to do - to retrieve the checked value of the current page (which I don't know how to do - I tried to write something like Magazine_Category = Model.MagazineCategories (this the property ID) and then

    switch (Magazine Category)
        {
            case "Gadgets": 
                MagazineID = 1022;
                break;
    
            case "Photography":
                MagazineID = 1023;
                break;
        }
    
        dynamic node = Library.NodeById(MagazineID);

     

    However, Model.MagazineCategories apparently do not retrieve the checked value ...

    What I need is the Text  - becasue then it will be easy to manage the category. Also the ID is fine, but it will be much better and much more clear to retrieve the text - because each text is the category - which I declared. 

     

    So, how can I access / retrieve the checked value of the current page ?

     

    Thanks. 

     

     

  • Moran 285 posts 934 karma points
    May 05, 2013 @ 15:09
    Moran
    0

    Checkbox property can be retrived by the following code:

    @if (Model.HasValue("Checkboxes"))
    {
    
        <ul>
            @foreach (string item in Model.Checkboxes.Split(','))
            {
                <li>@item</li>
            }
        </ul>
    }

    I advise you to take a look in this razor sample project really good work 

  • Meni 281 posts 539 karma points
    May 05, 2013 @ 17:41
    Meni
    0

    Thanks!

    Work.

    Is it possible also w/o a loop? Just to take the current? (which checked)

  • Moran 285 posts 934 karma points
    May 05, 2013 @ 19:50
    Moran
    0

    Yes 

    I think you can use only 

    @Model.Checkboxes

    this will give you only the selected value.

  • Charles Afford 1163 posts 1709 karma points
    May 06, 2013 @ 18:01
    Charles Afford
    0

    This seems a bit odd?  If you want to get the property value of a checkbox property

    int checkBoxValue;

    @if(Model.HasValue("Checkboxes")) //Check the property is avaliable
    {
        Int32.TryParse(@Model.GetPropery("Checkboxes").Value.ToString(), out checkBoxValue);
       
    <ul>

    if(checkBoxValue)  //SHOULD BE TRUE/FALSE

    {

    <li>@item</li>  //CHECKED

    }

    else

    {

    //NOT CHECKED

    }

           

        </
    ul>
    }

     

    Something like the above?  Charlie :)

  • Meni 281 posts 539 karma points
    May 06, 2013 @ 18:16
    Meni
    0

    Yes, Thanks! Work. But now I have another question:

    When I display the magazine I want to display it by categories, so for example once I dislay the "gadgets" I want to exclude all the nodes with the Photogrpahy Property and when display the "Photography" I want to exclude the "Gadgets". I wanted to use the "where" however, it's a proble because all the the Childrens (pages) are mix under one node (Gadgets + Photography) so actually I need to do it during the foreach look - the question is if I can sort the childrens before? It's mean - to get the property (category) of each children in the node before the loop?

  • Moran 285 posts 934 karma points
    May 07, 2013 @ 08:48
    Moran
    0

    I think you can use the "NodebyId" method in order to get the children from a specific category.

  • Charles Afford 1163 posts 1709 karma points
    May 07, 2013 @ 22:36
    Charles Afford
    0

    Moran, where do you get the id for the NodyById from and what happens if the node is recreated?

  • 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