x First time here? Check out the FAQ

Come work for Umbraco - The Umbraco HQ are hiring Project managers, .NET developers and DevOps people!

  • Avatar45posts65karma

    Get property name

    Matt Nolan started this topic February 29, 2012 @ 06:26, Go directly to the topic solution

    Hi,

    Does anyone know how to get the Name (not alias) of a property in Razor?

    thanks,

    Matt


  • Avatar133posts261karma
    Comment with ID: 109735
    Braydie posted this reply March 2, 2012 @ 03:57

    Hi Matt,

    If you are using a dynamic node you can just @MyDynamicNode.MyPropertyAlias and access it like that, or if you are using a regular Node, then you would do @MyNode.GetProperty("MyPropertyAlias")

    It's something like that! Hope I've pointed you in the right direction at least! :)


  • Avatar133posts261karma
    Comment with ID: 109738
    Braydie posted this reply March 2, 2012 @ 04:03

    Oops looks like I've misread your post!


  • Chris S. posted this reply March 2, 2012 @ 04:50

    It's just Name, e.g.

    DynamicModel.Children.First().ContentType.Name

    If you want to see all of them, you could try:

     

    @foreach (var child in DynamicModel.Children)
    {
        <textarea rows="40" cols="40"> 
    @foreach(PropertyDescriptor descriptor in TypeDescriptor.GetProperties(child.ContentType)) 
    { 
    string name=descriptor.Name; 
    object value=descriptor.GetValue(child.ContentType); 
    @Html.Raw(name + "=" + value +"\n") } 
    </textarea>
    }
    

    This forum really doesn't like you pasting code in


Please login or Sign up To post replies