John Smith
John Smith

Reputation: 131

How get model from modelmetadata?

In MVC 4 and 5 model metadata has property "Model"

In MVC 6 (ASP.Net core mvc), this property is gone.

So now, how do I get "Model" from model metadata?

Upvotes: 1

Views: 1307

Answers (1)

John Smith
John Smith

Reputation: 131

Found solution.

ViewData has ModelExplorer, where can find property by modelmetadata.

ViewData.ModelExplorer.Properties.SingleOrDefault(x => Equals(x.Metadata, metadata)).Model

Upvotes: 2

Related Questions