I have a page, which accepts a parameter x (which is a GUID). On the page I have a
HTML.DropDownListFor(x => x.SomeGuidProperty).
If I specify parameter x in URL as 43f67d68-066d-4fda-94a8-3e3e4c7c278a
(with dashes), drop down selects respeced option.
But if I specify parameter x in URL as 43f67d68066d4fda94a83e3e4c7c278a
(still GUID, but no dashes) - DropDownList ignores it.
It is impossible to ensure single format of GUID, as page is used by different sources.
What can be done to make DropDownList understand parameter x?
Instead of binding directly to a
Guid
, you'll need to bind to a string and then programmatically convert to aGuid
. For example, instead of something like:You'll need:
Then inside, you'll want to format
x
as aGuid
should be formatted, if it's not already before converting it to an actualGuid
:var guid = new Guid(x)
.