cameron
cameron

Reputation: 3006

What's the difference between @Model and @ViewData.Model?

In my view page, both seem work. But for @Model , visual studio tells me it's WebViewPage<T>.Model , and for @ViewData.Model, it is ViewDataDictionary<T>.Model. So what's the real difference there?

Upvotes: 10

Views: 2374

Answers (1)

nemesv
nemesv

Reputation: 139758

No there is no difference. In fact WebViewPage<T>.Model just calls ViewData.Model.

You can check the implementation on codeplex:

public abstract class WebViewPage<TModel> : WebViewPage
{
    //...

    public new TModel Model
    {
        get { return ViewData.Model; }
    }

    //...
}

Upvotes: 16

Related Questions