Dashless GUID不使用DropDownListFor [英] Dashless GUID not used DropDownListFor

查看:186
本文介绍了Dashless GUID不使用DropDownListFor的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网页,它接受一个参数x(它是一个GUID)。
在网页上我有一个

I have a page, which accepts a parameter x (which is a GUID). On the page I have a

HTML.DropDownListFor(x => x.SomeGuidProperty).

如果我指定的URL参数x为 43f67d68-066d-4fda-94a8-3e3e4c7c278a (破折号),下拉选择respeced选项。
但是,如果我指定的URL参数x为 43f67d68066d4fda94a83e3e4c7c278a (GUID依旧,但没有破折号) - DropDownList中忽略它。

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.

这是不可能的,以确保GUID的单个格式,页面用于由不同的来源。

It is impossible to ensure single format of GUID, as page is used by different sources.

什么可以做,使DropDownList的理解参数x?

What can be done to make DropDownList understand parameter x?

推荐答案

绑定到一个字符串,然后编程转换为的Guid 。例如,而不是这样的:

Instead of binding directly to a Guid, you'll need to bind to a string and then programmatically convert to a Guid. For example, instead of something like:

public ActionResult Foo(Guid x)

您需要:

public Actionresult Foo(string x)

然后在里面,你要格式化 X 的Guid 应格式化,如果不是已经其转换为前实际的Guid VAR GUID =新的GUID(X)

Then inside, you'll want to format x as a Guid should be formatted, if it's not already before converting it to an actual Guid: var guid = new Guid(x).

这篇关于Dashless GUID不使用DropDownListFor的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆