I am studying asp.net mvc and found something interesting:
It seems that I cannot explicitly determine the Model
view from the view with the error message stating that it has no setting.
@{ this.Model = "Hello" } //error
Then I looked at the source code in WebViewPage.cs and the View Model property actually looks like this:
public object Model { get { return ViewData.Model; } }
So the error.
But I wonder how I can do this: @{ ViewData.Model = "hello"; }
@{ ViewData.Model = "hello"; }
and really be able to use the @model
operator, the result is "hello"
I think I delve too much into this, but why is this so?
new to C # and ASP.NET
source share