Skip to content

[SelectFilter]

WARNING

This attribute only affects the generated Knockout HTML views - it does not enforce any relational rules in your data.

This attribute also currently has no effect against the Vue stack.

Specify a property to restrict dropdown menus by. Values presented will be only those where the value of the foreign property matches the value of the local property.

The local property name defaults to the same value of the foreign property.

Additionally, in place of a LocalPropertyName to check against, you may instead specify a static value using StaticPropertyValue to filter by a constant.

Example Usage

In this example, a dropdown for EmployeeRank created using @Knockout.SelectForObject in cshtml files will only present possible values of EmployeeRank which are valid for the EmployeeType of the Employee.

c#
public class Employee
{
    public int EmployeeId { get; set; }
    public int EmployeeTypeId { get; set; }
    public EmployeeType EmployeeType { get; set; }
    public int EmployeeRankId { get; set; }

    [SelectFilter(ForeignPropertyName = nameof(EmployeeRank.EmployeeTypeId), LocalPropertyName = nameof(Employee.EmployeeTypeId))]
    public EmployeeRank EmployeeRank { get; set; }
}

public class EmployeeRank
{
    public int EmployeeRankId { get; set; }
    public int EmployeeTypeId { get; set; }
    public EmployeeType EmployeeType { get; set; }
}
razor
<div>
    @(Knockout.SelectForObject<Models.Employee>(e => e.EmployeeRank))
</div>

Properties

public string ForeignPropertyName { get; set; }

The name of the property on the foreign object to filter against.

public string LocalPropertyName { get; set; }

The name of another property belonging to the class in which this attribute is used. The results of select lists will be filtered to match this value.

Defaults to the value of ForeignPropertyName if not set.

public string LocalPropertyObjectName { get; set; }

If specified, the LocalPropertyName will be resolved from the property by this name that resides on the local object.

This allows for querying against properties that are one level away from the current object.

public string StaticPropertyValue { get; set; }

A constant value that the foreign property will be filtered against. This string must be parsable into the foreign property's type to have any effect. If this is set, LocalPropertyName will be ignored.


Coalesce is a free and open-source framework created by IntelliTect to fill our desire to create better apps, faster. IntelliTect is a high-end software architecture and development consulting firm based in Spokane, Washington.

If you're looking for help with your software project, whether it be a Coalesce application, other technologies, or even just an idea, reach out to us at info@intellitect.com — we'd love to start a conversation! Our clients range from Fortune 100 companies to local small businesses and non-profits.