Class ItemViewModel
- Namespace
- Dynamicweb.Frontend
- Assembly
- Dynamicweb.dll
The Item
- Inheritance
-
Item
View Model
- Inherited Members
- Extension Methods
Remarks
With this view model, developers can efficiently interact with the item’s data, retrieving field values in various types (such as strings, booleans, dates, and more), and render them dynamically within the template.
The Item
This structure ensures that your Razor templates can be both powerful and clean, with minimal logic needed to handle data retrieval, allowing you to focus on presenting the content.
By leveraging the Item
Constructors
ItemViewModel()
Initializes a new instance of the Item
Properties
Fields
Gets a list of fields and their values for this item.
Property Value
- IList<Item
Field >View Model If you have defined an item type with 3 fields, you'll get a list of three fields and their values of this item instance
Id
Gets the item id.
Property Value
- string
E.g. '128'
Link
Gets a link (URL) to the page or paragraph that this item is attached to. If the item is not a page or paragraph this property is empty
Property Value
- string
The link. e.g. '/home' (Default.aspx?ID=1 if not using friendly URLs) or '/home#345'
PageID
Gets the page id if the item is attached to a page, row or a paragraph. If the item is attached to an area or user, this field is 0
Property Value
- int
E.g. '150'
ParagraphID
Gets the paragraph id if the item is attached to a paragraph. If the item is attached to an area, page, row or user, this field is 0
Property Value
- int
E.g. '1028'
SystemName
Gets the system name of the item type.
Property Value
- string
E.g. 'Swift_Page'
Methods
GetBoolean(string)
Gets the value of the specified field as a boolean.
Parameters
systemName
stringThe field system name.
Returns
- bool
true
orfalse
, which reflects the value stored in specified field. Fallback isfalse
Remarks
This method uses the Getfalse
is returned.
GetButton(string)
Gets a button view model if the field is a button field
Parameters
systemName
stringThe field system name.
Returns
GetColor(string)
Returns a color view model of the field.
Parameters
systemName
stringThe field system name.
Returns
- Color
View Model See Color
View , if the field contains a color view model, otherwiseModel null
Remarks
This method uses the Get
GetDateTime(string)
Returns the date and time data value of the specified field.
Parameters
systemName
stringThe field system name.
Returns
- Date
Time The date and time data value of the specified field. Fallback is
DateTime.MinValue
Remarks
This method uses the GetDateTime.MinValue
is returned.
GetDecimal(string)
Returns the decimal value of the specified field.
Parameters
systemName
stringThe field system name.
Returns
- decimal
The decimal value of the specified field. Fallback is
0
Remarks
This method uses the Get
GetDouble(string)
Returns the double value of the specified field.
Parameters
systemName
stringThe field system name.
Returns
- double
The double value of the specified field. Fallback is
0
Remarks
This method uses the Get
GetField(string)
Returns the view model of the field.
Parameters
systemName
stringThe field system name.
Returns
GetFile(string)
Returns a file view model of the field.
Parameters
systemName
stringThe field system name.
Returns
Remarks
This method uses the Get
GetFiles(string)
Returns a list of file view models of the field.
Parameters
systemName
stringThe field system name.
Returns
- IList<File
View >Model See IList<T>
Remarks
This method uses the Get
GetGeolocation(string)
Returns a geolocation view mode of the field.
Parameters
systemName
stringThe field system name.
Returns
Remarks
This method uses the Get
GetGoogleFont(string)
Returns a google font view model of the field.
Parameters
systemName
stringThe field system name.
Returns
Remarks
This method uses the Get
GetInt32(string)
Returns the 32-bit integer value of the field.
Parameters
systemName
stringThe field system name.
Returns
- int
The 32-bit integer value of the specified field. Fallback is
0
Remarks
This method uses the Get
GetInt64(string)
Returns the 64-bit integer value of the field.
Parameters
systemName
stringThe field system name.
Returns
- long
The 64-bit integer value of the specified field. Fallback is
0
Remarks
This method uses the Get
GetItem(string)
Returns an item view model of the field.
Parameters
systemName
stringThe field system name.
Returns
Remarks
This method uses the Get
The field's editor type should be the item editor.
GetItems(string)
Returns a list of item view model of the field.
Parameters
systemName
stringThe field system name.
Returns
- IList<Item
View >Model See IList<T>
Remarks
This method uses the Get
The field's editor type should be the item relation list editor.
GetLink(string)
Returns a link view model of the field.
Parameters
systemName
stringThe field system name.
Returns
Remarks
This method uses the Get
GetList(string)
Returns a list view model of the field.
Parameters
systemName
stringThe field system name.
Returns
Remarks
This method uses the Get
GetRawValue(string)
Returns the raw unmodified value from the database without any parsing
Parameters
systemName
stringThe field system name.
Returns
- object
An object of the values underlying database type. Int, String, Boolean etc. Never another view model or object
GetRawValueString(string)
Returns the raw unmodified value from the database without any parsing but converted to string
Parameters
systemName
stringThe field system name.
Returns
- string
A string of the underlying raw value.
GetRawValueString(string, string?)
Returns the raw unmodified value from the database without any parsing but converted to string. Returns the default value if the field value is null or empty.
Parameters
systemName
stringThe field system name.
defaultValue
stringValue to return if the field does not return any value
Returns
- string
A string of the underlying raw value.
GetString(string)
Returns the value of the field as string.
Parameters
systemName
stringThe field system name.
Returns
- string
The string value of the specified field.
Remarks
ToString
is called on whatever object is returned on the field
GetString(string, string?)
Returns the value of the field as string. Returns the default value if the field value is null or empty.
Parameters
systemName
stringThe field system name.
defaultValue
stringValue to return if the field is null or empty
Returns
- string
A string of the underlying raw value.
Remarks
This method uses the Get
GetUser(string)
Gets a User
Parameters
systemName
stringThe field system name.
Returns
GetUserGroup(string)
Gets a User
Parameters
systemName
stringThe field system name.
Returns
GetUserGroups(string)
Gets a collection of User
Parameters
systemName
stringThe field system name.
Returns
- IList<User
Group >View Model A collection of User
Group .View Model
GetUsers(string)
Returns a list of user view models of the field.
Parameters
systemName
stringThe field system name.
Returns
- IList<User
View >Model See IList<T>
Remarks
This method uses the Get
GetValue(string)
Returns the value of the field.
Parameters
systemName
stringThe field system name.
Returns
- object
System.Object
; The instance of the object would be one of the item view model types
Remarks
This method uses the Get
GetValue<T>(string)
Returns the value of the field.
Parameters
systemName
stringThe field system name.
Returns
- T
The value of the specified field as type
T
, or null if the field is not found or the value cannot be converted to typeT
.
Type Parameters
T
The type to which the value should be converted. This type is one of the item field view models.
Remarks
This method uses the Get
GetVideo(string)
Gets a video view model if the field is a media field
Parameters
systemName
stringThe field system name.
Returns
TryGetButton(string, out ButtonViewModel?)
Using the systemName
to retrieve an item field using Gettrue
.
Parameters
systemName
stringUsed to look up the corresponding Button
View if it exists on the item.Model button
ButtonView Model The
out
ButtonView value from the method.Model
Returns
- bool
true
ifbutton
is not null, otherwisefalse
TryGetColor(string, out ColorViewModel?)
Using the systemName
to retrieve an item field using Gettrue
.
Parameters
systemName
stringThe field system name.
color
ColorView Model When this method returns, contains the Color
View value, if the field is found; otherwise,Model null
.
Returns
- bool
true
ifcolor
is not null, otherwisefalse
Remarks
This method uses the Get
TryGetDateTime(string, out DateTime)
Returns true if the value of the field is specified and a date time is assigned to the passed out parameter.
Parameters
systemName
stringThe field system name.
dateTime
DateTime When this method returns, contains the System.DateTime value equivalent of the field value, if the field exists, otherwise
DateTime.MinValue
.
Returns
- bool
true
if the field value was converted successfully; otherwise,false
Remarks
This method uses the Getfalse
is returned and DateTime.MinValue
is assigned to the dateTime
parameter.
TryGetField(string, out ItemFieldViewModel?)
Returns true if the value of the field is specified and a item field view model is assigned to the passed out parameter.
Parameters
systemName
stringThe field system name.
itemField
ItemField View Model When this method returns, contains the Item
Field value, if the field exists, otherwiseView Model null
.
Returns
- bool
true
ifitemField
is not null, otherwisefalse
Remarks
This method uses the Get
TryGetFile(string, out FileViewModel?)
Returns true if the value of the field is specified and a file view model is assigned to the passed out parameter.
Parameters
systemName
stringThe field system name.
file
FileView Model When this method returns, contains the File
View value, if the field exists, otherwiseModel null
.
Returns
- bool
true
iffile
is not null, otherwisefalse
Remarks
This method uses the Get
TryGetFiles(string, out IList<FileViewModel>?)
Returns true if the value of the field is specified and a list of file view models is assigned to the passed out parameter.
Parameters
systemName
stringThe field system name.
files
IList<FileView >Model When this method returns, contains the IList<T> value, if the field exists, otherwise
null
.
Returns
- bool
true
iffiles
is not null, otherwisefalse
Remarks
This method uses the Get
TryGetGeolocation(string, out GeolocationViewModel?)
Returns true if the value of the field is specified and a geolocation view model is assigned to the passed out parameter.
Parameters
systemName
stringThe field system name.
geolocation
GeolocationView Model When this method returns, contains the Geolocation
View value, if the field exists, otherwiseModel null
.
Returns
- bool
true
ifgeolocation
is not null, otherwisefalse
Remarks
This method uses the Get
TryGetGoogleFont(string, out GoogleFontViewModel?)
Returns true if the value of the field is specified and a google font view model is assigned to the passed out parameter.
Parameters
systemName
stringThe field system name.
googleFont
GoogleFont View Model When this method returns, contains the Google
Font value, if the field exists, otherwiseView Model null
.
Returns
- bool
true
ifgoogleFont
is not null, otherwisefalse
Remarks
This method uses the Get
TryGetImageFile(string, out ImageFileViewModel?)
Returns true if the value of the field is specified and an imagefile view model is assigned to the passed out parameter.
Parameters
systemName
stringThe field system name.
image
ImageFile View Model When this method returns, contains the Image
File value, if the field exists, otherwiseView Model null
.
Returns
- bool
true
ifimage
is not null, otherwisefalse
Remarks
This method uses the Get
TryGetImageFiles(string, out IEnumerable<ImageFileViewModel>?)
Returns true if the value of the field is specified and a list of imagefile view models is assigned to the passed out parameter.
Parameters
systemName
stringThe field system name.
images
IEnumerable<ImageFile >View Model When this method returns, contains the IEnumerable<T> value, if the field exists, otherwise
null
.
Returns
- bool
true
ifimages
is not null, otherwisefalse
Remarks
This method uses the Get
TryGetItem(string, out ItemViewModel?)
Returns true if the value of the field is specified and an item view model is assigned to the passed out parameter.
Parameters
systemName
stringThe field system name.
item
ItemView Model When this method returns, contains the Item
View value, if the field exists, otherwiseModel null
.
Returns
- bool
true
ifitem
is not null, otherwisefalse
Remarks
This method uses the Get
TryGetItems(string, out IList<ItemViewModel>?)
Returns true if the value of the field is specified and a list of item view models is assigned to the passed out parameter.
Parameters
systemName
stringThe field system name.
items
IList<ItemView >Model When this method returns, contains the IList<T> value, if the field exists, otherwise
null
.
Returns
- bool
true
ifitems
is not null, otherwisefalse
Remarks
This method uses the Get
TryGetLink(string, out LinkViewModel?)
Returns true if the value of the field is specified and a link view model is assigned to the passed out parameter.
Parameters
systemName
stringThe field system name.
link
LinkView Model When this method returns, contains the Link
View value, if the field is found; otherwise,Model null
.
Returns
- bool
true
iflink
is not null, otherwisefalse
Remarks
This method uses the Get
TryGetList(string, out ListViewModel?)
Returns true if the value of the field is specified and a list view model is assigned to the passed out parameter.
Parameters
systemName
stringThe field system name.
list
ListView Model When this method returns, contains the List
View value, if the field is found; otherwise,Model null
.
Returns
- bool
true
iflist
is not null, otherwisefalse
Remarks
This method uses the Get
TryGetString(string, out string?)
Returns true if the value of the field is specified and a string is assigned to the passed out parameter.
Parameters
systemName
stringThe field system name.
value
stringWhen this method returns, contains the string value equivalent of the field value, if the field exists, otherwise
null
.
Returns
- bool
true
ifvalue
is not null and not empty, otherwisefalse
Remarks
This method uses the Get
TryGetUser(string, out UserViewModel?)
Using the systemName
to retrieve an item field using Getnull
, the method returns false
, otherwise true
.
Parameters
systemName
stringUsed to look up the corresponding User
View if it exists on the item.Model user
UserView Model The
out
UserView value from the method.Model
Returns
- bool
true
ifuser
is not null, otherwisefalse
.
TryGetUserGroup(string, out UserGroupViewModel?)
Using the systemName
to retrieve an item field using Getnull
, the method returns false
, otherwise true
.
Parameters
systemName
stringUsed to look up the corresponding User
Group if it exists on the item.View Model userGroup
UserGroup View Model The
out
UserGroup value from the method.View Model
Returns
- bool
true
ifuserGroup
is not null, otherwisefalse
.
TryGetUserGroups(string, out IList<UserGroupViewModel>?)
Using the systemName
to retrieve an item field using Getnull
or an empty collection, the method returns false
, otherwise true
.
Parameters
systemName
stringUsed to look up the corresponding User
Group if it exists on the item.View Model userGroups
IList<UserGroup >View Model The
out
UserGroup value from the method.View Model
Returns
- bool
true
ifuserGroups
is not null and has elements, otherwisefalse
.
TryGetUsers(string, out IList<UserViewModel>?)
Returns true if the value of the field is specified and a list of user view models is assigned to the passed out parameter.
Parameters
systemName
stringThe field system name.
users
IList<UserView >Model When this method returns, contains the IList<T> value, if the field is found; otherwise,
null
.
Returns
- bool
true
ifusers
is not null, otherwisefalse
Remarks
This method uses the Get
TryGetValue<T>(string, out T?)
Returns true if the value of the field is specified and some value of type T is assigned to the passed out parameter.
Parameters
systemName
stringThe field system name.
value
TWhen this method returns, contains the value of type
T
, if the field is found; otherwise,null
.
Returns
- bool
true
ifvalue
is not null, otherwisefalse
Type Parameters
T
The type to which the value should be converted. This type is one of the item field view models.
Remarks
This method uses the GetValue<T>(string) method to retrieve the value of the field.
TryGetVideo(string, out VideoViewModel?)
Using the systemName
to retrieve an item field using Gettrue
.
Parameters
systemName
stringUsed to look up the corresponding Video
View if it exists on the item.Model video
VideoView Model The
out
VideoView value from the method.Model
Returns
- bool
true
ifvideo
is not null, otherwisefalse