Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialCecilia Benítez
1,396 Pointsin razor I have @model MyFirstWebsite.Models.Modelo and I want to achieve @model MyFirstWebsite.Models.Modelo.Receta
Modelo is a container for my other "child" models but in razor how can I do ".Receta" if visual studio doesn't give me the option.. the only code I have in Modelo is: '''C# namespace MyFirstWebsite.Models { public class Modelo { public List<Receta> Receta { get; set; } public List<Slide> Slide { get; set; } } } '''
2 Answers
Cecilia Benítez
1,396 Pointsyes I was mising an using directive I have
public class Modelos
{
public Receta Receta { get; set; }
public Slide Slide { get; set; }
public Receta[] Recetas { get; set; }
}
thanks a lot
Steven Parker
231,269 PointsFrom the system's point of view, "Receta" isn't a model but a property of the "Modelo" model. So if you pass that model to your razor page, you should be able to access the property with dot notation: "@Model.Receta
".
Steven Parker
231,269 PointsTo the person who down-voted this answer...
I'd appreciate your feedback about why you found this answer unacceptable, and what I could do to make it better.
Cecilia Benítez
1,396 PointsCecilia Benítez
1,396 PointsI have another problem now when I pass "Model.Recetal" in my foreach loop I pass null but I sopose to pass an id, this causes an exeption.. how can avoid this?