Link to home
Start Free TrialLog in
Avatar of HugoHiasl
HugoHiasl

asked on

MVC Razor how to loop through nested data?

Hi,

I have a data structure with nested location objects and in every level of the loction object is it possible to have resources assigned.

[u]Location-Object[/u]
Id
ParentLocation
LocationName

[u]Resource-Object[/u]
Id
LocationId
ResourceName



--Location
  -- Location
    -- Resource
    -- Resource
-- Location
  -- Resource

Open in new window


Now I would like to render it using RAZOR in a nested way. Normally I would use recursive methods for it. But I don't think that's possible with RAZOR

what is the best practice for something like this?
ASKER CERTIFIED SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of HugoHiasl
HugoHiasl

ASKER

The @helper and @functions keywords were the part that I did not know... I am fairly new to MVC... Thanks.
Normally, once you are inside a Razor block you don't need to prefix your code with an @. However, in my testing (and research) I found that when you call one helper from another you need to prefix the call with the @. This is why lines 9, 21, and 28 have the leading @.