Interface ITypedModel
Object in partial Razor files to access parameters handed in. Example caller:
@Html.Partial(someFile, new { blogPost, file = mainFile, title = "hello" }
Example partial:
var blogPost = MyModel.Item("BlogPost");
var file = MyModel.File("File");
var title = MyModel.String("Title");
Tip
The common data types such as string
or ITypedItem have methods to quickly get them in the desired type.
This allows things such as var message = MyModel.String("Message");
For less common types you'll need to use Get(string, NoParamOrder, bool?) and cast it as needed, like this:
string message = MyModel.Get("Message");
.
[PublicApi]
public interface ITypedModel
Remarks
Introduced in v16.02
Methods
Bool(string, NoParamOrder, bool?, bool?)
Will get the value and return in the desired type.
bool Bool(string name, NoParamOrder protector = default, bool? fallback = null, bool? required = null)
Parameters
name
stringProperty name on the passed in data object
protector
NoParamOrderfallback
bool?The optional fallback value.
required
bool?Throw error if
name
doesn't exist, see Convention: Property Required Name Checks. It is automaticallyfalse
if afallback
is set / notnull
.
Returns
- bool
typed result if found, false if not found.
Code(string, NoParamOrder, object, bool?)
Get code forwarded to the current razor.
Code was usually created in the caller using GetCode(...)
and may need to be passed around.
dynamic Code(string name, NoParamOrder protector = default, object fallback = null, bool? required = null)
Parameters
name
stringProperty name on the passed in data object
protector
NoParamOrderfallback
objectA fallback to use if not found - not commonly used here.
required
bool?Throw error if
name
doesn't exist, see Convention: Property Required Name Checks. It is automaticallyfalse
if afallback
is notnull
.
Returns
- dynamic
The resulting object is
dynamic
which is necessary for making calls to methods etc.
Remarks
New in 16.05
ContainsKey(string)
Check if this typed object has a property of this specified name. It's case-insensitive.
bool ContainsKey(string name)
Parameters
name
stringthe name like
Image
; some objects also support path to sub-property likeAuthor.Name
Returns
Remarks
Adding in 16.03 (WIP)
DateTime(string, NoParamOrder, DateTime?, bool?)
Will get the value and return in the desired type.
DateTime DateTime(string name, NoParamOrder protector = default, DateTime? fallback = null, bool? required = null)
Parameters
name
stringProperty name on the passed in data object
protector
NoParamOrderfallback
DateTime?The optional fallback value.
required
bool?Throw error if
name
doesn't exist, see Convention: Property Required Name Checks. It is automaticallyfalse
if afallback
is set / notnull
.
Returns
- DateTime
typed result if found, default-date if not found.
Decimal(string, NoParamOrder, decimal?, bool?)
Will get the value and return in the desired type.
decimal Decimal(string name, NoParamOrder protector = default, decimal? fallback = null, bool? required = null)
Parameters
name
stringProperty name on the passed in data object
protector
NoParamOrderfallback
decimal?The optional fallback value.
required
bool?Throw error if
name
doesn't exist, see Convention: Property Required Name Checks. It is automaticallyfalse
if afallback
is notnull
.
Returns
- decimal
int result if found,
0
if not found/convertible.
Exceptions
- ArgumentException
if the name is not found and no fallback provided and required not false
Double(string, NoParamOrder, double?, bool?)
Will get the value and return in the desired type.
double Double(string name, NoParamOrder protector = default, double? fallback = null, bool? required = null)
Parameters
name
stringProperty name on the passed in data object
protector
NoParamOrderfallback
double?The optional fallback value.
required
bool?Throw error if
name
doesn't exist, see Convention: Property Required Name Checks. It is automaticallyfalse
if afallback
is notnull
.
Returns
- double
int result if found,
0
if not found/convertible.
Exceptions
- ArgumentException
if the name is not found and no fallback provided and required not false
File(string, NoParamOrder, IFile, bool?)
Will get the value if specified. If the value is a list of files, then this will only return the first one.
IFile File(string name, NoParamOrder protector = default, IFile fallback = null, bool? required = null)
Parameters
name
stringProperty name on the passed in data object
protector
NoParamOrderfallback
IFileThe optional fallback value.
required
bool?Throw error if
name
doesn't exist, see Convention: Property Required Name Checks. It is automaticallyfalse
if afallback
is set / notnull
.
Returns
- IFile
typed result if found,
null
if not found.
Files(string, NoParamOrder, IEnumerable<IFile>, bool?)
Will get the value if specified. If the value is a single file, will return a list containing that file.
IEnumerable<IFile> Files(string name, NoParamOrder protector = default, IEnumerable<IFile> fallback = null, bool? required = null)
Parameters
name
stringProperty name on the passed in data object
protector
NoParamOrderfallback
IEnumerable<IFile>The optional fallback value.
required
bool?Throw error if
name
doesn't exist, see Convention: Property Required Name Checks. It is automaticallyfalse
if afallback
is set / notnull
.
Returns
- IEnumerable<IFile>
typed result if found, empty-list if not found.
Float(string, NoParamOrder, float?, bool?)
Will get the value and return in the desired type.
float Float(string name, NoParamOrder protector = default, float? fallback = null, bool? required = null)
Parameters
name
stringProperty name on the passed in data object
protector
NoParamOrderfallback
float?The optional fallback value.
required
bool?Throw error if
name
doesn't exist, see Convention: Property Required Name Checks. It is automaticallyfalse
if afallback
is notnull
.
Returns
- float
int result if found,
0
if not found/convertible.
Exceptions
- ArgumentException
if the name is not found and no fallback provided and required not false
Folder(string, NoParamOrder, IFolder, bool?)
Will get the value if specified. If the value is a list of folders, then this will only return the first one.
IFolder Folder(string name, NoParamOrder protector = default, IFolder fallback = null, bool? required = null)
Parameters
name
stringProperty name on the passed in data object
protector
NoParamOrderfallback
IFolderThe optional fallback value.
required
bool?Throw error if
name
doesn't exist, see Convention: Property Required Name Checks. It is automaticallyfalse
if afallback
is set / notnull
.
Returns
- IFolder
typed result if found,
null
if not found.
Folders(string, NoParamOrder, IEnumerable<IFolder>, bool?)
Will get the value if specified. If the value is a single folder, will return a list containing that folder.
IEnumerable<IFolder> Folders(string name, NoParamOrder protector = default, IEnumerable<IFolder> fallback = null, bool? required = null)
Parameters
name
stringProperty name on the passed in data object
protector
NoParamOrderfallback
IEnumerable<IFolder>The optional fallback value.
required
bool?Throw error if
name
doesn't exist, see Convention: Property Required Name Checks. It is automaticallyfalse
if afallback
is set / notnull
.
Returns
- IEnumerable<IFolder>
typed result if found, empty-list if not found.
Get(string, NoParamOrder, bool?)
Will get the value and return as object, since the type isn't known.
object Get(string name, NoParamOrder protector = default, bool? required = null)
Parameters
name
stringProperty name on the passed in data object
protector
NoParamOrderrequired
bool?throw error if
name
doesn't exist, see Convention: Property Required Name Checks
Returns
- object
Object if found,
null
if not found.
Get<T>(string, NoParamOrder, T, bool?)
Will get the value and return as type T as specified.
T Get<T>(string name, NoParamOrder protector = default, T fallback = default, bool? required = null)
Parameters
name
stringProperty name on the passed in data object
protector
NoParamOrderfallback
TThe fallback value. If provided, the type is automatically determined.
required
bool?Throw error if
name
doesn't exist, see Convention: Property Required Name Checks. It is automaticallyfalse
if afallback
is provided which is not thedefault
. So likeGet<string>(..., fallback: false)
can't be detected, but..., fallback: "hello"
can.
Returns
- T
Object of type T if found,
null
if not found.
Type Parameters
T
The returned type
Gps(string, NoParamOrder, GpsCoordinates, bool?)
Will get the value and return in the desired type.
GpsCoordinates Gps(string name, NoParamOrder protector = default, GpsCoordinates fallback = null, bool? required = null)
Parameters
name
stringProperty name on the passed in data object
protector
NoParamOrderfallback
GpsCoordinatesThe optional fallback value.
required
bool?Throw error if
name
doesn't exist, see Convention: Property Required Name Checks. It is automaticallyfalse
if afallback
is notnull
.
Returns
- GpsCoordinates
GpsCoordinates if found, null if not found/convertible.
Remarks
Added in 17.08
Exceptions
- ArgumentException
if the name is not found and no fallback provided and required not false
Guid(string, NoParamOrder, Guid?, bool?)
Will get the value and return in the desired type.
Guid Guid(string name, NoParamOrder protector = default, Guid? fallback = null, bool? required = null)
Parameters
name
stringProperty name on the passed in data object
protector
NoParamOrderfallback
Guid?The optional fallback value.
required
bool?Throw error if
name
doesn't exist, see Convention: Property Required Name Checks. It is automaticallyfalse
if afallback
is set / notnull
.
Returns
- Guid
typed result if found, empty-guid if not found.
HtmlTag(string, NoParamOrder, IHtmlTag, bool?)
Will get the value being an IHtmlTag
as specified (RazorBlade objects)
IHtmlTag HtmlTag(string name, NoParamOrder protector = default, IHtmlTag fallback = null, bool? required = null)
Parameters
name
stringProperty name on the passed in data object
protector
NoParamOrderfallback
IHtmlTagThe optional fallback value.
required
bool?Throw error if
name
doesn't exist, see Convention: Property Required Name Checks. It is automaticallyfalse
if afallback
is notnull
.
Returns
- IHtmlTag
typed result if found,
null
if not found
HtmlTags(string, NoParamOrder, IEnumerable<IHtmlTag>, bool?)
Will get the value being an list (IEnumerable) of IHtmlTag
as specified (RazorBlade objects)
IEnumerable<IHtmlTag> HtmlTags(string name, NoParamOrder protector = default, IEnumerable<IHtmlTag> fallback = null, bool? required = null)
Parameters
name
stringProperty name on the passed in data object
protector
NoParamOrderfallback
IEnumerable<IHtmlTag>The optional fallback value.
required
bool?Throw error if
name
doesn't exist, see Convention: Property Required Name Checks. It is automaticallyfalse
if afallback
is notnull
.
Returns
- IEnumerable<IHtmlTag>
typed result if found,
null
if not found
Int(string, NoParamOrder, int?, bool?)
Will get the value and return in the desired type.
int Int(string name, NoParamOrder protector = default, int? fallback = null, bool? required = null)
Parameters
name
stringProperty name on the passed in data object
protector
NoParamOrderfallback
int?The optional fallback value.
required
bool?Throw error if
name
doesn't exist, see Convention: Property Required Name Checks. It is automaticallyfalse
if afallback
is notnull
.
Returns
- int
int result if found,
0
if not found/convertible.
Exceptions
- ArgumentException
if the name is not found and no fallback provided and required not false
Item(string, NoParamOrder, ITypedItem, bool?)
Will get the value if specified. If the value is a list of items, then this will only return the first one.
ITypedItem Item(string name, NoParamOrder protector = default, ITypedItem fallback = null, bool? required = null)
Parameters
name
stringProperty name on the passed in data object
protector
NoParamOrderfallback
ITypedItemThe optional fallback value.
required
bool?Throw error if
name
doesn't exist, see Convention: Property Required Name Checks. It is automaticallyfalse
if afallback
is set / notnull
.
Returns
- ITypedItem
typed result if found,
null
if not found.
Items(string, NoParamOrder, IEnumerable<ITypedItem>, bool?)
Will get the value if specified. If the value is a single item, will return a list containing that item.
IEnumerable<ITypedItem> Items(string name, NoParamOrder protector = default, IEnumerable<ITypedItem> fallback = null, bool? required = null)
Parameters
name
stringProperty name on the passed in data object
protector
NoParamOrderfallback
IEnumerable<ITypedItem>The optional fallback value.
required
bool?Throw error if
name
doesn't exist, see Convention: Property Required Name Checks. It is automaticallyfalse
if afallback
is set / notnull
.
Returns
- IEnumerable<ITypedItem>
typed result if found, empty-list if not found.
Keys(NoParamOrder, IEnumerable<string>)
Get all the keys available in this Model (all the parameters passed in). This is used to sometimes run early checks if all the expected parameters have been provided.
IEnumerable<string> Keys(NoParamOrder protector = default, IEnumerable<string> only = null)
Parameters
protector
NoParamOrderonly
IEnumerable<string>Only return the keys specified here, if found. Typical use:
only: new [] { "Key1", "Key2" }
. Useful to check if all or any specific keys exist.
Returns
Remarks
Added in 16.03
String(string, NoParamOrder, string, bool?)
Will get the value and return in the desired type.
string String(string name, NoParamOrder protector = default, string fallback = null, bool? required = null)
Parameters
name
stringProperty name on the passed in data object
protector
NoParamOrderfallback
stringThe optional fallback value.
required
bool?Throw error if
name
doesn't exist, see Convention: Property Required Name Checks. It is automaticallyfalse
if afallback
is notnull
.
Returns
- string
typed result if found,
null
if not found.
Toolbar(string, NoParamOrder, IToolbarBuilder, bool?)
Will get the value being a toolbar as specified.
IToolbarBuilder Toolbar(string name, NoParamOrder protector = default, IToolbarBuilder fallback = null, bool? required = null)
Parameters
name
stringProperty name on the passed in data object
protector
NoParamOrderfallback
IToolbarBuilderThe optional fallback value.
required
bool?Throw error if
name
doesn't exist, see Convention: Property Required Name Checks. It is automaticallyfalse
if afallback
is set / notnull
.
Returns
- IToolbarBuilder
typed result if found,
null
if not found