C# 如何在查询字符串中检查段
我得到以下错误,但由于某种原因,它的guid在uril中不可用。我想我可以检查一下是否为空,当然,密钥不存在 这不是一个重复的问题,它询问如何检查它自己的实际密钥,看看它是否存在C# 如何在查询字符串中检查段,c#,asp.net,C#,Asp.net,我得到以下错误,但由于某种原因,它的guid在uril中不可用。我想我可以检查一下是否为空,当然,密钥不存在 这不是一个重复的问题,它询问如何检查它自己的实际密钥,看看它是否存在 Line 23: Line 24: player _player = new player(); Line 25: Guid id = new Guid(Request.QueryString["id"].ToString()); Li
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"]);
改变这种方式
Guid id = new Guid(Request.QueryString["id"] ?? "");
if (id == Guid.Empty)
…您得到的错误是什么?请求。QueryString[“id”]已经是一个字符串,如果它的null调用ToString()是一个坏主意。它是一个null错误,所以它是,但我不会仍然得到null
string id=Request.QueryString[“id”];如果(!string.IsNullOrEmpty(id)){…使用它…}
g
是Guid()构造函数参数的内部名称,则传递null作为其值,该值无效,因此会出现错误。感谢您的支持,这将引发;新Guid(“”)不比新Guid(null)更有效,它在System.FormatException:无法识别的Guid格式中仍然显示Guid。您必须向其传递一个有效的Guid字符串,如果您的id值不存在,您没有Guid字符串,您想做什么?因此,如果没有id,您需要一个新的Guid?-><代码>字符串id=Request.QueryString[“id”];var guid=string.IsNullOrEmpty(id)?新Guid():新Guid(id)代码>