Reputation: 27703
Ok, it may be a silly question, but how do I reference my ViewModel object that I passed to the View in asp.net mvc?
so say my controller action has this at the end
return View(myModelObject);
in my view, how do I refer to it? Please use razor syntax.
Upvotes: 1
Views: 108
Reputation: 2744
You just need 2 steps
use @model in the header of your view (with small letter m)
@model MyNamespace.MyModelObject
use the mode in your code inside a block or line statement as the following
Line
@Model
Block
@{
Model
}
and remember you will use capital letter M
Upvotes: 2
Reputation: 218808
You can use @inherits
of @model
in the header of the view. Then, in the view's code, the object Model
is a statically-typed reference to your model.
Upvotes: 1
Reputation:
You can reference it by the Model
property of the ViewDataDictionary
object. Something like this to reference your ViewModel's property:
@{string StringVariable = Model.YourViewModelStringProperty;}
Upvotes: 2