[英]How do i convert Context.User.Identity.GetUserId() to int with c# in asp.net vs2015
How do I convert Context.User.Identity.GetUserId() to an int. 如何将Context.User.Identity.GetUserId()转换为int。
code: 码:
string clientId = Context.User.Identity.GetUserId();
if (clientId != null) {
cart NewInCart = new cart();
NewInCart.ClientId = Convert.ToInt32(clientId);
}
Above code gives error stating: 上面的代码给出了错误说明:
when converting a string to DateTime, parse the string to take the date before putting each variable into the DateTime object. 将字符串转换为DateTime时,在将每个变量放入DateTime对象之前,分析字符串以获取日期。
我认为您想要的是:
NewInCart.ClientId = Int32.Parse(clientId);
Sorted for now. 现在排序。
I have decided to change the data type of ClientID in the dbo to nvarchar(50);
我决定将dbo中ClientID的数据类型更改为nvarchar(50);
that way I save like this: 这样,我这样保存:
string clientId = Context.User.Identity.GetUserId() ;
.......
cart.ClientId = clientId;
where cart.ClientId
is now expecting a string. 其中cart.ClientId
现在需要一个字符串。 This sorted my problem and I no longer need to convert Context.User.Identity.GetUserId()
to int. 这解决了我的问题,我不再需要将Context.User.Identity.GetUserId()
转换为int。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.