Misbit
Misbit

Reputation: 347

Can't get to property in razor foreach

I'm still fairly new to MVC and Razor and I'm hoping you can help me out with something. I am able to use the following code to just print the line (using @reply.GetProperty("PropertyName") but when I try to assign it to a variable (test) the code fails. Why is this and how can I get around it? I really need to be able to assign it and use it further in some other code.

    @foreach (var reply in CurrentPage.Children)
    {
        @reply.GetProperty("PropertyName")
        @{
            string test = reply.GetProperty("PropertyName");
        }
    }

Upvotes: 0

Views: 54

Answers (1)

Shivkumar
Shivkumar

Reputation: 1903

In your View

@{
   string test = string.Empty;
 }

@foreach (var reply in CurrentPage.Children)
    {
        @reply.GetProperty("PropertyName")
        test = reply.GetProperty("PropertyName");

    }

Upvotes: 1

Related Questions