Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

How can I send a Injected generic type to a generic component in Blazor

$
0
0

I get the syntax-error int the 'Grid1Component.razor' file.The syntax is:The type 'T' in the generic type or method 'IGenericCrudService'. There is no boxing conversion or type parameter conversion from 'T' to 'BaseEntity'.

I'm using .Net9 and Blazor.

My Index.razor file:

@namespace OqtaneLibrary.DefaultGridModule1TEST@inherits ModuleDataBase@inject IGenericCrudService<Activity> _genericCrudServiceGrid1 <Grid1Component T="Activity"                _genericCrudServiceGrid1="_genericCrudServiceGrid1" />@code {}

And my Grid1Component looks like this:

@namespace OqtaneLibrary.Components@typeparam T @* @typeparam T where T : OqtaneLibrary.Models.BaseEntity  // Gives syntax error - Unexpected literals following the typeparam directive. expected 'line-break'  *@@code {    [Parameter]    public IGenericCrudService<T> _genericCrudServiceGrid1 { get; set; }  // Syntax error on this stmt.}

and the GenericCrusService looks like this:

 public interface IGenericCrudService<T> where T : BaseEntity {     Task<T> Get(int entityId, int SiteId,  int ModuleId,  string include = null);...}

and the startup has this definition:

services.AddTransient(typeof(IGenericCrudService<>), typeof(GenericCrudService<>));    // Generic service

Any idea?Thanks.


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>