-
Notifications
You must be signed in to change notification settings - Fork 86
viewdata element
Declares an accessor property for a piece of view data.
<viewdata x="T1" y="T2" />
Results in C#:
public T1 x { get { return (T1)ViewData.Eval("x"); } }
public T2 y { get { return (T2)ViewData.Eval("y"); } }
<viewdata x="T1" y="T2" default="d"/>
Results in C#:
public T1 x { get { return (T1)(ViewData.Eval("x") ?? d); } }
public T2 y { get { return (T2)(ViewData.Eval("y") ?? d); } }
Adds a fall-back value for the property in cases where the actual view data is missing or null.
<viewdata x="T1 anyName1" y="T2 anyName2" />
Results in C#:
public T1 anyName1 { get { return (T1)ViewData.Eval("x"); } }
public T2 anyName2 { get { return (T2)ViewData.Eval("y"); } }
A name following the type will determine the name of the property which is added. This enables you to declare viewdata
accessors which contain dashes or dots, which are not allowed in property names.
Provides a generic parameter to strongly type the Model
of the view's base class.
Note: The use of (model/Model) is case sensitive - take special note of the usage
<viewdata model="T1" />
Results in C#:
public class generated_view_name : base_view_name<T1>
{
public T1 Model { get { return ViewData.Model; } }
}
The base view class is strongly typed, and a typed property named Model
is added to the generated view.
<viewdata model="T1 anyName" />
Results in C#:
public class generated_view_name : base_view_name<T1>
{
public T1 Model { get { return ViewData.Model; } }
public T1 anyName { get { return ViewData.Model; } }
}
A name following the type causes an additional property of that name to be added as an alias for the Model
property.