ModelToComponentMapper 0.9.0.1-alpha
See the version list below for details.
dotnet add package ModelToComponentMapper --version 0.9.0.1-alpha
NuGet\Install-Package ModelToComponentMapper -Version 0.9.0.1-alpha
<PackageReference Include="ModelToComponentMapper" Version="0.9.0.1-alpha" />
<PackageVersion Include="ModelToComponentMapper" Version="0.9.0.1-alpha" />
<PackageReference Include="ModelToComponentMapper" />
paket add ModelToComponentMapper --version 0.9.0.1-alpha
#r "nuget: ModelToComponentMapper, 0.9.0.1-alpha"
#:package ModelToComponentMapper@0.9.0.1-alpha
#addin nuget:?package=ModelToComponentMapper&version=0.9.0.1-alpha&prerelease
#tool nuget:?package=ModelToComponentMapper&version=0.9.0.1-alpha&prerelease
Model to Component Mapper
Blazor Model to Component Mapper
Example Component
NavItemView.razor
Note the inheritance of ViewComponentBase
and the use the @Model. Future release will not require the use of a base class but a known property name that is of type TModel
@using ModelToComponentMapper
@inherits ViewComponentBase<NavItem>
<li class="nav-item px-3">
<NavLink class="nav-link" href="@Model.Href" Match="@Model.NavLinkMatch">
<span class="@Model.Icon" aria-hidden="true"></span> @Model.Text
</NavLink>
</li>
Usage
This is overkill for only one model type it is just an example of view registration within a .razor component.
<ModelView Source="DataSource.NavItems">
<ViewRegistration TModel="NavItem" TComponent="NavItemView" />
</ModelView>
You can register all your components in program.cs (Functionality not complete. Registration here should only be defaults that can be over written not replaced.)
In program.cs
var viewModelComponentSelector = new ViewModelComponentSelector();
viewModelComponentSelector.RegisterDefaults();
viewModelComponentSelector.RegisterView<NavItem, NavItemView>();
builder.Services.AddScoped<IViewSelector>(sp => viewModelComponentSelector);
@using ModelToComponentMapper
@page "/"
<ModelView Source="FakeDataSource.BlogItems" />
produced this:
from this:
DataSource.cs
public static class FakeDataSource
{
public static readonly IReadOnlyList<object> BlogItems = new object[]
{
new Heading { Text = "Hello World!", Level= HeadingLevel.One },
new Division { Text = "Welcome to my" },
new Anchor { Text = "My Website.", Href ="https://brianparker.azurewebsites.net/" },
new Division { Text = "All these items are being rendered based on their data type and order from an enumerable object source" },
new ImageSource { DisplayHeight=259, DisplayWidth=241, Source = imageData },
new Division { Text = "Pretty cool, huh?" },
new Markup { Text = stackFlare }
};
public static readonly IReadOnlyList<object> NavItems = new object[]
{
new NavItem { Text = "Home", Icon ="oi oi-home" , Href ="" , NavLinkMatch = NavLinkMatch.All },
new NavItem { Text = "By Layout", Icon ="oi oi-code" , Href ="byLayout" },
new NavItem { Text = "By Code", Icon ="oi oi-excerpt" , Href ="byCode" }
};
private const string imageData = "data:image/jpeg; base64, (truncated)";
private const string stackFlare = "<a href=\"https://stackoverflow.com/users/1492496/brian-parker\" target=\"_blank\"><img src=\"https://stackoverflow.com/users/flair/1492496.png?theme=dark\" width=\"208\" height=\"58\" alt=\"profile for Brian Parker at Stack Overflow, Q & A for professional and enthusiast programmers\" title=\"profile for Brian Parker at Stack Overflow, Q & A for professional and enthusiast programmers\"></a>";
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 is compatible. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net5.0
- Microsoft.AspNetCore.Components.Web (>= 5.0.0-rc.1.20451.17)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on ModelToComponentMapper:
Package | Downloads |
---|---|
OrakTech.BlazorToast
Enables Bootstaps Toast's in blazor. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last Updated |
---|---|---|
1.0.2.13 | 648 | 12/11/2020 |
1.0.2.12 | 481 | 12/10/2020 |
1.0.2.4 | 462 | 11/14/2020 |
1.0.2 | 475 | 11/10/2020 |
1.0.1.1 | 355 | 11/3/2020 |
1.0.1 | 291 | 10/10/2020 |
1.0.0 | 334 | 10/9/2020 |
0.9.1-beta | 298 | 10/7/2020 |
0.9.0.2-alpha | 360 | 10/7/2020 |
0.9.0.1-alpha | 295 | 10/6/2020 |