To View Component or To Not View Component (that is the forum post)
j

jacksorjacksor (Richard Jackson)

about 1 year ago
Hej! Actually doing some Umbraco 13 work and wanted to sense check my use of View Components. Example: - Rootpage with multiple Tracks (listed as "Singles", because music init) - Want to display details of each Track in a card - Want to move the code for each of these cards into a dedicated component, passing the Track instance as an parameter My general approach would be to make a View Component (
TrackCardViewComponent.cs
) which returns the code for the card, using input of
@model Track
. I've included the code at the end of this message. This works just fine - I more or less want to confirm this is the correct approach, or if I'm over-complicating things. My crucial reason for using the View Component was to pass the Track instance as an parameter to the card, but that might be possible via other means. All comments/advice/direction appreciated! Rich Rootpage.cshtml:
<div class="row row-cols-3 p-0 m-0">
     @foreach (Track track in Model.Singles)
     {
         @await Component.InvokeAsync("TrackCard", track)
     }
 </div>
TrackCardViewComponent.cs:
public class TrackCardViewComponent : ViewComponent
{
    public IViewComponentResult Invoke(Track track)
    {
        return View("~/Views/ViewComponents/TrackCard.cshtml", track);
    }
}
TrackCard.cshtml:
@model Track

@if (Model.TrackArtwork is null) return;
<div class="col-sm-6 col-md-4 p-2">
    <img class="w-100" src="@Model.TrackArtwork.MediaUrl()" />
    <p>@Model.Name | @Model.TrackArtwork.MediaUrl()</p>
    <p>Test</p>
</div>
System.InvalidOperationException: Unknown provider name "Microsoft.Data.SqlClient" (SOLVED)
d

Dennis Bidstrup

over 1 year ago
Hi. I'm trying to upgrade from Umbraco 12 to 13. I have changed the dotnet versions, and upgraded the Umbraco nuget packages. But know I get an error stating it cant finde Microsoft.Data.SqlClient The first error I got was: BootFailedException: Boot failed: Umbraco cannot run. See Umbraco's log file for more details. -> Umbraco.Cms.Core.Exceptions.BootFailedException: Unattended installation failed. -> Umbraco.Cms.Core.Exceptions.UnattendedInstallException: Unattended installation failed. -> System.ArgumentException: The specified invariant name 'Microsoft.Data.SqlClient' wasn't found in the list of registered .NET Data Providers. at System.Data.Common.DbProviderFactories.GetFactory(String providerInvariantName, Boolean throwOnError) Then I added, DbProviderFactories.RegisterFactory("Microsoft.Data.SqlClient", SqlClientFactory.Instance); And now I get: BootFailedException: Boot failed: Umbraco cannot run. See Umbraco's log file for more details. -> Umbraco.Cms.Core.Exceptions.BootFailedException: The database configuration failed. Please check log file for additional information (can be found in '/Umbraco/Data/Logs/') -> Umbraco.Cms.Core.Exceptions.UnattendedInstallException: The database configuration failed. Please check log file for additional information (can be found in '/Umbraco/Data/Logs/') -> System.InvalidOperationException: Unknown provider name "Microsoft.Data.SqlClient" at Umbraco.Cms.Infrastructure.Persistence.DbProviderFactoryCreator.GetSqlSyntaxProvider(String providerName) Anyone know how to fix this?