dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.36k stars 9.99k forks source link

Blazor - support GUID conversion in parameters #10837

Closed LaughingJohn closed 5 years ago

LaughingJohn commented 5 years ago

Hi, I'm using Blazor (client side). I have a page used to edit records that I want to take the type of record and the Id. My route looks like this @page "/edit/{EntityName}/{id}"

I have my parameters like this:

` [Parameter] public string EntityName { get; set; }

[Parameter]
public Guid Id { get; set; }`

As you can see Id is actually a GUID and this is throwing a cast error and failing to convert:

WASM: System.InvalidOperationException: Unable to set property 'id' on object of type 'TestProject.Blazor.Pages.EditForm'. The error was: Specified cast is not valid. ---> System.InvalidCastException: Specified cast is not valid.

Obviously I can change it to a string and convert it myself, but it would be nice to be able to have it happen automatically. I haven't tested but I guess this may also bet true of other types.

Thanks!

LaughingJohn commented 5 years ago

Sorry, just realised you can specify {id:guid}. Issue closed!