Can I use a value object a Blazor route? #729
-
Not strictly, a Vogen question, but I'd be surprised if no Vogen user had come across this before, so thought it would be a good place to ask. I have a Blazor app, and one page shows the details of a company. Before adding Vogen to the app, the first line of the component looked like this... @page $"/company-{{Id:int}}" The component had a corresponding parameter as follows... [Parameter]
public int Id { get; set; } That worked fine. I've now installed Vogen, and changed the type of the [ValueObject]
public partial struct CompanyId; I changed the @page $"/company-{{Id:CompanyId}}" ...and changed the type of the parameter to match, but this gives a run-time exception...
I tried adding the following... builder.Services.Configure<RouteOptions>(opt => opt.ConstraintMap.Add("CompanyId", typeof(CompanyId))); ...which required me to change the value object to look like this... [ValueObject]
public partial struct CompanyId : IParameterPolicy; ...but this gave a run-time exception...
My guess is that I've got the wrong thing as the first parameter to Anyone able to help? Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
I'm pretty sure it can be used in Blazor. I'm not able to test at the moment, but when I'm back online, I'll give this scenario a try (and add a project to the Samples folder). |
Beta Was this translation helpful? Give feedback.
-
@MrYossu Unfortunately, Vogen ids cannot be used in Blazor routes. This is a Blazor limitation, in that it does not yet respect |
Beta Was this translation helpful? Give feedback.
@MrYossu Unfortunately, Vogen ids cannot be used in Blazor routes. This is a Blazor limitation, in that it does not yet respect
IParseable<>
or any other mechanism for providing a parse function to the route system. This is a limitation I've found in my work with Vogen and Blazor as well.