I'm trying to pass my model to my view in Razor. With the old method, I could define it at the top of the file (the model).
I did some googling, and thought I figured it out - doesn't seem to be working. I'm not getting any intellisense on the model.
Top of the View file:
@Model CodySolution.Models.PhotoModel
@{
ViewBag.Title = "Photography";
Layout = "~/Views/Shared/_master.cshtml";
}
Where I'm using the Model:
<ul class="nav nav-pills nav-stacked margin-top">
@foreach (var cat in Model.Categories)
{
<li class="active"><a href="#">@cat</a></li>
}
</ul>
Is this the correct way to define it?
In case someone is looking for the exact syntax, here it is:
@model CodySolution.Models.PhotoModel
@{
ViewBag.Title = "Photography";
Layout = "~/Views/Shared/_master.cshtml";
}
Note the lowercase @model
since uppercase prints the value of the Model
property.
@Model
prints the value of the Model
property.
To declare the model type, use the @model
directive.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With