在Asp.Net Core 2.2控制器上,我有以下内容:
var url1 = Url.Action(action: "GetContentByFileId", values: new { FileId = 1 });
var url2 = _linkGenerator.GetUriByAction(HttpContext, action: "GetContentByFileId", values: new { FileId = 1 });
我在URL1中获得了正确的url,但URL2为空...
我正在将LinkGenerator注入Controller中,并且它不是null,所以我认为还可以...
对我想念的东西有任何想法吗?
答案 0 :(得分:2)
在第二个调用中包括预期的控制器。
ActionContext
第一个调用已经通过注入UrlHelper
的当前 let group = DispatchGroup()
var runningTotal: Double = 0.00
ref.observeSingleEvent(of: .value) { (snapshot) in
guard let bills = snapshot.value as? [String: AnyObject] else {
//error
return
}
for billId in bills.keys {
group.enter()
print("Entering")
Database.database().reference().child("bills").child(billId).observeSingleEvent(of: .value, with: { (snapshot) in
guard let bill = snapshot.value as? [String: AnyObject] else {
return
}
if let amount = bill["amount"] as? Double {
runningTotal += amount
}
group.leave()
print("Leaving")
})
}
completion(runningTotal)
}
group.wait()
}
知道了控制器