我的 if 条件为什么没有返回结果?我的 if 条件是否有问题?

huangapple go评论65阅读模式
英文:

Why does my if condition not return the result? Is my if condition wrong?

问题

我想要实现一个if条件,如果我的Model.Reference在数据库中已经存在ID,就不生成ID或调用_sysautoController.GUID

我希望当Model.Reference不为空时,不生成ID或调用_sysautoController.GUID,而当Model.Reference为空或空字符串时,才调用_sysautoController.GUID来生成ID

这是我尝试过的代码:

if (Model.Reference != null)
{

}
else if (Model.Reference == null)
{
    _sysautoController.GUID(1, Model.TranCompNo);
}
英文:

I want to implement an if condition to not generate ID or call the _sysautoController.GUID if my Model.Reference has an ID that already exists in the database.

I want it to not generate ID or call _sysautoController.GUID if Model.Reference is not null, and if Model.Reference is null or empty, that's the time it will call _sysautoController.GUID to generate an ID.

Here is my code that I have tried

if (Model.Reference != null)
{
            
}
else if (Model.Reference == null)
{
    _sysautoController.GUID(1, Model.TranCompNo);
}

答案1

得分: 1

以下是翻译的内容:

也许你可以尝试这样做

if (Model.Reference != null)
{
            
}
else
{
    _sysautoController.GUID(1, Model.TranCompNo);
}
英文:

Maybe you can try it just like this

if (Model.Reference != null)
{
            
}
else
{
    _sysautoController.GUID(1, Model.TranCompNo);
}

huangapple
  • 本文由 发表于 2023年7月3日 09:58:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/76601467.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定