Asp.net 奇怪的Guid.NewGuid()行为
我在网站上搜索了这个问题的答案,但我似乎无法找到这个答案 我已经多次使用NewGuid()方法,效果非常好。但现在由于某种原因,它创建了一个空Guid 这是我的密码:Asp.net 奇怪的Guid.NewGuid()行为,asp.net,c#-4.0,Asp.net,C# 4.0,我在网站上搜索了这个问题的答案,但我似乎无法找到这个答案 我已经多次使用NewGuid()方法,效果非常好。但现在由于某种原因,它创建了一个空Guid 这是我的密码: // Class of the Guid Object public class CardUserAccount { // User ID of the user's profile public Guid UserId { get; set; } } //Page object
// Class of the Guid Object
public class CardUserAccount
{
// User ID of the user's profile
public Guid UserId { get; set; }
}
//Page object where method is called
Public partial class CreateSale : System.Web.UI.UserControl
{
// Create the UserProfile object
public CardUserAccount profile = new CardUserAccount();
protected void ContinueButton_Click(object sender, EventArgs e)
{
Guid _userId = Guid.NewGuid();
profile.UserId = _userId;
}
protected void SubmitButton_Click(object sender, EventArgs e)
{
// Method to add object to database
SubmitProfile(profile);
}
然后,我调用一个简单的linq-to-entities方法将对象添加到实体对象中
我已经仔细检查了它,我不会在任何地方覆盖它
但是,在page_load方法之外创建概要文件对象可能是个问题。我认为这不会影响回发期间的对象
非常感谢您的帮助这是实际代码吗?因为你声明并初始化了变量,然后什么也不做
如果要覆盖字段值,则不应在此方法中声明该字段。多编写一点代码就好了,因为当前您没有使用该Guid执行任何操作。也许这就是问题所在?你在这里继续的过程是什么?您可能在其他事件中覆盖了生成的guid。我在撰写一篇评论时说了几乎相同的话。我认为这是答案,但我们只是猜测,直到我们看到更多的代码