【问题标题】:Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx). error?Guid 应包含 32 位数字和 4 个破折号 (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)。错误?
【发布时间】:2016-01-08 06:35:29
【问题描述】:

我需要将这六个字段保存在同一列中,但不保存在同一行和同一单元格中。每个字段都有默认 GUID。所以我决定将默认 guid 放在一个列表中,将字段放在一个列表中,然后在我们想要的地方调用该特定列表的对象。

       ArrayList Alist = new ArrayList();
        {
            Alist.Add("FD713788-B5AE-49FF-8B2C-F311B9CB0CC4");
            Alist.Add("64B512E7-46AE-4989-A049-A446118099C4");
            Alist.Add("376D45C8-659D-4ACE-B249-CFBF4F231915");
            Alist.Add("59A2449A-C5C6-45B5-AA00-F535D83AD48B");
            Alist.Add("03ADA903-D09A-4F53-8B67-7347A08EDAB1");
            Alist.Add("2F405521-06A0-427C-B9A3-56B8931CFC57");
        }

        ArrayList objValue = new ArrayList();
        {
            objValue.Add(viewmodel.TinNo);
            objValue.Add(viewmodel.CstNo);
            objValue.Add(viewmodel.PanNo);
            objValue.Add(viewmodel.CinNo);
            objValue.Add(viewmodel.ExciseRegNo);
            objValue.Add(viewmodel.ServiceTaxNo);
        }

   var TaxInfoTaxFiledclassobj = new TaxInfoTaxFiled()
        {

            TaxInfoTaxFieldID = TaxInfoTaxFieldObj,
            TaxFieldID = new Guid(Alist .ToString ()),
            FieldValue = objValue.ToString(),
        };

一切正常 但在 TaxFieldID 中,它显示了从列表中计算的计数,但在保存时显示以下错误

我该怎么办?

【问题讨论】:

  • DON"T 添加代码图片,它们没有用。添加实际代码
  • 以文本格式发布您的代码和错误
  • 好的,等我添加我的代码

标签: c# asp.net-mvc-4 collections


【解决方案1】:

您正在尝试将 ArrayList 作为 Guid 传递。在这一行:

TaxFieldID = Guid.Parse(Alist.ToString())

您只需选择ArrayList 的元素之一进行解析。此外,您可以使用List<Guid> 来完全消除该问题。

List<Guid> guidList = new List<Guid>();
guidList.Add(new Guid("DDE4BA55-808E-479F-BE8B-72F69913442F"));

...

TaxFieldID = guidList[0]; // obviously, select the appropriate GUID

【讨论】:

  • 史蒂夫请告诉我按照您所说的添加我的默认 guid 以及如何按照您所说的添加我的六个字段
  • 我刚刚把答案的相关部分,其余的代码将与您的相同。这只是处理设置 Guid 值。
  • 但我需要将这 6 个 guid 逐行保存在同一列中,这是我的要求
  • 你是指每个 Guid 的一行,还是一行中一列中的所有 Guid,可能用逗号或其他东西分隔?
  • 是的,我需要按以下格式将每个 guid 保存在同一列的逐行中 [在此处输入图像描述][1] [1]:i.stack.imgur.com/42dkd.png
【解决方案2】:

Guid.Parse() 能够解析 GUID。 Alist.ToString() 不应是 GUID。

编辑

我猜你正在寻找这样的东西 -

var listFiled = new List<TaxInfoTaxFiled>();
for(var item = 0; item < objValue.Count ; item++)
{
    listFiled.Add(new TaxInfoTaxFiled
    {

        TaxInfoTaxFieldID = TaxInfoTaxFieldObj,
        TaxFieldID = new Guid(Alist[item]),
        FieldValue = objValue[item]
    });
}

【讨论】:

  • 我也试过这个 TaxFieldID = Guid.parse(Alist.Tostring()),这也显示同样的错误
  • 显然是,因为 Alist 不是 Guid。你在找什么?
  • 现在我需要传递 TaxFieldID 中的六个 guid 和 fievalue 中的六个字段
  • 一种方法是对数组中的每个元素使用Guid.Parse(),然后在分配之前连接到一个字符串。
  • 如果我连接意味着所有值都保存在同一列同一单元格中。但我需要以以下格式保存i.stack.imgur.com/42dkd.png
【解决方案3】:

AList 是一个数组,而不是 Guid

您必须对AList 的条目执行Guid.Parse

有点像

foreach(string g in AList)
{
     Guid guid = Guid.Parse(g);
     // Guid guid = new Guid(g) also works
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多