C# 非静态字段、方法或属性“System.Web.UI.Page.RouteData.get”需要对象引用
我正在开发asp.net应用程序。在这个应用程序中,我使用Url重写方法在浏览器中显示页面。每当任何人想要编辑任何记录时,我已检查要编辑的“ID”是否为空,如下所示:C# 非静态字段、方法或属性“System.Web.UI.Page.RouteData.get”需要对象引用,c#,asp.net,url-rewriting,webmethod,C#,Asp.net,Url Rewriting,Webmethod,我正在开发asp.net应用程序。在这个应用程序中,我使用Url重写方法在浏览器中显示页面。每当任何人想要编辑任何记录时,我已检查要编辑的“ID”是否为空,如下所示: if (Page.RouteData.Values["ID"] != null) { } 如果此条件为真,则表示希望编辑通过的id记录 Page.RouteData.Values["ID"] 从表单中显示所有数据。如果上述条件在任何webMethod中未使用,但在webMethod中使用,则会出现错误 我的方法是 [Syst
if (Page.RouteData.Values["ID"] != null)
{
}
如果此条件为真,则表示希望编辑通过的id记录
Page.RouteData.Values["ID"]
从表单中显示所有数据。如果上述条件在任何webMethod中未使用,但在webMethod中使用,则会出现错误
我的方法是
[System.Web.Script.Services.ScriptMethod()]
[System.Web.Services.WebMethod(e)]
public static string SaveData(string Category,string SubCategory,string ProductType)
{
try
{
ProductBrand objBrand = new ProductBrand();
DataTable dt = new DataTable();
ProductType objProductType = new ProductType();
objProductType.SubCategoryID = Convert.ToInt64(SubCategory);
objProductType.ProductTypeName = ProductType;
if (Page.RouteData.Values["ID"] != null)
{
objProductType.TypeID = Convert.ToInt64(Page.RouteData.Values["ID"].ToString());
objProductType.Flag = "U";
else
{
dt = new ProductType().SelectByCategory(objProductType.SubCategoryID, objProductType.ProductTypeName);
if (dt.Rows.Count > 0)
{
objProductType.Flag = "D";
}
else
{
objProductType.Flag = "I";
}
}
if (objProductType.Flag.Equals("D"))
{
objBrand.BrandID = 2;
}
else
{
int retval = new ProductType().Insert(objProductType);
if (retval > 0)
{
objBrand.BrandID = 1;
}
else
{
objBrand.BrandID = 0;
}
}
return objBrand.BrandID.ToString();
}
catch (Exception ex)
{
throw (ex);
}
}
上面的webmethod是为了使用jquery将数据插入数据库而编写的。在上面的webmethod语句中,如果Page.RouteData.Values[ID]!=null错误显示为
An object reference is required for the non-static field, method, or property 'System.Web.UI.Page.RouteData.get'
但是当我在webmethod之外使用上述条件时,这个错误不会出现。请在这里帮助我。尝试删除函数SaveData中的static并调用like instance
var xx = new YOURCLASS();
xx.SaveData(xx,yy,zz);
我不能这么说,因为SaveData是一个WebMethod,在这里使用jquery插入数据