从request.querystring中删除字符



我有一些代码从如下url获取DrawingId:

/队列/Queue.aspx ?模式= Autosearch& DrawingID = 188320 "

我的问题是在运行程序的另一部分之后,url变成了:

/队列/Queue.aspx ?模式= Autosearch& DrawingID = 188320 ? DrawingRequestId = 376333, doQuerySearch = true&开始=,=结束,印第安纳州=,=模型及状态= Open&经理=,=来源及受让人=,title =, =特性及部分=,不是=,=客户,数量=,=项目,startIndex = 1, endIndex = 10,页大小= 10,总= 193,日期= Extended& qsEnd =

有没有一种好方法可以删除188320之后的所有内容?也有一个很好的方法来提取376333的drawingrequesttid ?

下面是DrawingID的代码:
public string DrawingId
{
  get
  {
   if (Request.QueryString["DrawingID"] != "" && Request.QueryString["DrawingID"] != null)
   {
     return Request.QueryString["DrawingID"];
   }
  return null;
  }
}

这部分不会运行,因为DrawingId变得不正确:

List<string> featureCodes = drawingBusiness.GetFeatureCodesByDrawingId(long.Parse(DrawingId));

这段代码不起作用,因为DrawingId只是188320,

变成188320?DrawingRequestId = 376333

这里是我假设问题开始的javascript:

function CloseAndRefresh() {
        var parentUrl = window.top.location.href;
        if (parentUrl.indexOf("Queue/Queue.aspx") != -1) {
            if (window.location.search === "") {
                window.location.href = window.top.location
            }
            else {
                window.top.location.href = window.top.location + window.location.search;
            }
        }
        else {
            if (window.location.search === "") {
                window.location.href = window.top.location
            }
            else {
                window.top.location.href = window.top.location + window.location.search;
            }
        }
    }

要删除附加到url的所有代码,可以这样做:

var longURL = "/Queue/Queue.aspx?Mode=Autosearch&DrawingID=188320?DrawingRequestId=376333&doQuerySearch=true&start=&end=&Ind=&Model=&status=Open&manager=&source=&assignee=&title=&features=&parts=&pas=&customer=&number=&project=&startIndex=1&endIndex=10&pageSize=10&total=193&date=Extended&qsEnd=";
var shortURL = longURL.split('?').slice(0, -1).join('?');
console.log(shortURL) // "/Queue/Queue.aspx?Mode=Autosearch&DrawingID=188320"

要提取DrawingRequestId,您可以执行以下操作:

var longURL = "/Queue/Queue.aspx?Mode=Autosearch&DrawingID=188320?DrawingRequestId=376333&doQuerySearch=true&start=&end=&Ind=&Model=&status=Open&manager=&source=&assignee=&title=&features=&parts=&pas=&customer=&number=&project=&startIndex=1&endIndex=10&pageSize=10&total=193&date=Extended&qsEnd=";
var drawingRequestId = parseInt(longURL.substr(longURL.indexOf('DrawingRequestId=')+17, 6));
console.log(drawingRequestId) // 376333

相关内容

  • 没有找到相关文章

最新更新