Using VS2012 and MVC4, how can I obtain the current model's name?
I want to dynamically name some variables using the model name itself. Is there a way? I have found controllers and actions, but not any model info, yet.
Have you tried this?
@model.GetType().Name
As @Rowan Freeman notes in the comment below, you can also do this from the model itself:
GetType().Name; // or this.GetType().Name;
... or this from a controller:
var model = new MyCustomViewModel();
var modelName = model.GetType().Name;
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