C
C#•3y ago
Indeed

Namespace cannot directly contain members Error [Answered]

@model SharedProject.Models.Api.WeatherEndpoint.WeatherResponse?
@inject IStringLocalizer<SharedResource> SharedLocalizer
@using SharedProject.Localization
@using BWASM.Pages
@using Microsoft.AspNetCore.Mvc.TagHelpers
@using Microsoft.Extensions.Localization

@{ViewData["Title"] = "Home Page";}

<div class="text-center">
<h1 class="display-4">@SharedLocalizer["Hello"] @GetUsername()</h1>
<component type="typeof(Counter)" render-mode="WebAssemblyPrerendered"/>
<p>Weather Forecasts: @Model?.Forecasts.Count</p>

<component type="typeof(Faq)" render-mode="WebAssemblyPrerendered" headerText="All claims" desc="@AllClaims"/>
<component type="typeof(Faq)" render-mode="WebAssemblyPrerendered" headerText="User Claims" desc="@UserClaims"/>
<component type="typeof(Faq)" render-mode="WebAssemblyPrerendered" headerText="Token Claims" desc="@TokenClaims"/><
/div>

@{
private readonly List<string> _userClaimTypes = new() {
};

private readonly List<string> _tokenClaimTypes = new() {
};

private Dictionary<string, string> UserClaims => User.Claims.Where(x => _userClaimTypes.Contains(x.Type)).ToDictionary(c
=> c.Type, c => c.Value);
private Dictionary<string, string> TokenClaims => User.Claims.Where(x =>
_tokenClaimTypes.Contains(x.Type)).ToDictionary(c => c.Type, c => c.Value);
private Dictionary<string, string> AllClaims => User.Claims.ToDictionary(c => c.Type, c => c.Value);

string GetUsername() {
string? username = ViewData["Username"]?.ToString();
return string.IsNullOrEmpty(username) ? "New User" : username;
}
}
@model SharedProject.Models.Api.WeatherEndpoint.WeatherResponse?
@inject IStringLocalizer<SharedResource> SharedLocalizer
@using SharedProject.Localization
@using BWASM.Pages
@using Microsoft.AspNetCore.Mvc.TagHelpers
@using Microsoft.Extensions.Localization

@{ViewData["Title"] = "Home Page";}

<div class="text-center">
<h1 class="display-4">@SharedLocalizer["Hello"] @GetUsername()</h1>
<component type="typeof(Counter)" render-mode="WebAssemblyPrerendered"/>
<p>Weather Forecasts: @Model?.Forecasts.Count</p>

<component type="typeof(Faq)" render-mode="WebAssemblyPrerendered" headerText="All claims" desc="@AllClaims"/>
<component type="typeof(Faq)" render-mode="WebAssemblyPrerendered" headerText="User Claims" desc="@UserClaims"/>
<component type="typeof(Faq)" render-mode="WebAssemblyPrerendered" headerText="Token Claims" desc="@TokenClaims"/><
/div>

@{
private readonly List<string> _userClaimTypes = new() {
};

private readonly List<string> _tokenClaimTypes = new() {
};

private Dictionary<string, string> UserClaims => User.Claims.Where(x => _userClaimTypes.Contains(x.Type)).ToDictionary(c
=> c.Type, c => c.Value);
private Dictionary<string, string> TokenClaims => User.Claims.Where(x =>
_tokenClaimTypes.Contains(x.Type)).ToDictionary(c => c.Type, c => c.Value);
private Dictionary<string, string> AllClaims => User.Claims.ToDictionary(c => c.Type, c => c.Value);

string GetUsername() {
string? username = ViewData["Username"]?.ToString();
return string.IsNullOrEmpty(username) ? "New User" : username;
}
}
I do not understand the issue here at all? Maybe there are some invisible characters?
8 Replies
Indeed
IndeedOP•3y ago
althought it does formats weird in @{}
Angius
Angius•3y ago
Doesn't Blazor use @code {} for the, well, code?
Indeed
IndeedOP•3y ago
oh didnt specify, its an mvc client with blazor wasm in a diff project @section Scripts also doesnt work for some reason
Angius
Angius•3y ago
If that's MVC, then I'd move that code to the controller anyway That's for loading Javascript
Indeed
IndeedOP•3y ago
oh XD, Okay, I've tried to mover to @code {} and now i get
Indeed
IndeedOP•3y ago
Indeed
IndeedOP•3y ago
ye, but right now playing around if my component is formatted properly for my needs tried removing
<component type="typeof(Faq)" render-mode="WebAssemblyPrerendered" headerText="All claims" desc="@AllClaims"/>
<component type="typeof(Faq)" render-mode="WebAssemblyPrerendered" headerText="User Claims" desc="@UserClaims"/>
<component type="typeof(Faq)" render-mode="WebAssemblyPrerendered" headerText="Token Claims" desc="@TokenClaims"/>
<component type="typeof(Faq)" render-mode="WebAssemblyPrerendered" headerText="All claims" desc="@AllClaims"/>
<component type="typeof(Faq)" render-mode="WebAssemblyPrerendered" headerText="User Claims" desc="@UserClaims"/>
<component type="typeof(Faq)" render-mode="WebAssemblyPrerendered" headerText="Token Claims" desc="@TokenClaims"/>
but didnt change anything It seems that the problem was with me using Dictionary getter???
Dictionary<string, string> UserClaims() {
return User.Claims.Where(x => _userClaimTypes.Contains(x.Type)).ToDictionary(c
=> c.Type, c => c.Value);
}
Dictionary<string, string> UserClaims() {
return User.Claims.Where(x => _userClaimTypes.Contains(x.Type)).ToDictionary(c
=> c.Type, c => c.Value);
}
OK1
Dictionary<string, string> UserClaims {
get{
return User.Claims.Where(x => _userClaimTypes.Contains(x.Type)).ToDictionary(c
=> c.Type, c => c.Value);
}
}
Dictionary<string, string> UserClaims {
get{
return User.Claims.Where(x => _userClaimTypes.Contains(x.Type)).ToDictionary(c
=> c.Type, c => c.Value);
}
}
🚫 !close
Accord
Accord•3y ago
āœ… This post has been marked as answered!

Did you find this page helpful?