【发布时间】:2015-11-10 14:55:59
【问题描述】:
我收到以下错误,但由于某种原因,它在 uri 中不可用的 guid 上,我想我可以检查一下是否为空,但当然密钥不存在
这不是重复它询问如何检查它自己的实际密钥以查看它是否存在。 !!!
Line 23:
Line 24: player _player = new player();
Line 25: Guid id = new
Guid(Request.QueryString["id"].ToString());
Line 26: if (id == Guid.Empty)
Line 27: {
这是整个代码
protected void Page_Load(object sender, EventArgs e)
{
try
{
player _player = new player();
Guid id = new Guid(Request.QueryString["id"].ToString());
if (id == Guid.Empty)
{
}
else
{
_player = _dal.GetPlayerBYID(id);
if (!Page.IsPostBack)
{
if (_player.Name != null)
txtFullName.Text = _player.Name;
if (_player.address != null)
txtAddress.Text = _player.address;
dlGenders.SelectedValue = _player.gender;
}
}
var dlGendersSource = _dal.GetGenders();
dlGenders.DataSource = dlGendersSource;
dlGenders.DataValueField = "LookupValue";
dlGenders.DataTextField = "LookupDescription";
dlGenders.DataBind();
string message = "";
if (Context.User.IsInRole("canEdit"))
{
//enable edit controls on page
message += "This user can edit a record";
}
else if (Context.User.IsInRole("canDelete"))
{
//enable delete controls on page
message += "This user can delete a record.";
}
else if (Context.User.IsInRole("canAdd"))
{
//enable delete controls on page
message += "This user can add a record.";
}
RadNotification1.Position = NotificationPosition.BottomRight;
RadNotification1.Text = message;
}
catch (Exception ex)
{
throw new EntityContextException("Page Load Failed in Edit Players .", ex);
}
}
显示错误的屏幕截图这会导致团队一开始并不总是附加玩家 ID,因此我需要能够处理该问题,直到调用保存更改。
伙计们,这是我遇到问题的部分,所以没有反对意见!!!!
Guid id = new Guid(Request.QueryString["id"]);
【问题讨论】:
-
你遇到了什么错误?
-
Request.QueryString["id"] 已经是一个字符串,如果它的 null 调用 ToString() 是个坏主意。
-
它是一个空错误,所以它是但我不会仍然得到空值
-
string id = Request.QueryString["id"]; if (!string.IsNullOrEmpty(id)) { ... use it ...} -
g是 Guid() 构造函数参数内部名称,您将 null 作为其值传递,这是无效的,因此会出现错误。