我试图在一些进程后用外部javascript文件中的这个语句刷新页面.
window.location.href = window.location.href
Run Code Online (Sandbox Code Playgroud)
它完美地重新加载页面,但我想在重新加载后滚动到特定位置.所以,我把它放在页面上.
<a name="uploadImgSection"></a>
Run Code Online (Sandbox Code Playgroud)
并将javascript更改为
window.location.href = window.location.href + "#mypara";
Run Code Online (Sandbox Code Playgroud)
此代码也不会重新加载/刷新页面
window.location.hash = "#uploadImgSection";
window.location.href = window.location.href;
Run Code Online (Sandbox Code Playgroud)
当我这样做时,它根本不会重新加载页面.有什么办法可以用滚动条位置重新加载页面吗?
我知道有些人会争论“为什么不将 SyncMethod() 设为异步方法呢?”。我们希望如此,但在现实世界中,有时出于向后兼容性的原因,我们必须保持 SyncMethod 的原样。
情况是这样的。下面的代码导致我们陷入僵局。
public void SyncMethod()
{
var serviceResult = ProcessDataAsync().Result;
}
public await ServiceResult ProcessDataAsync()
{
//Do other things
await GetDataFromApiAsync();
}
private static HttpClient Client = new HttpClient();
public await ApiResult GetDataFromApiAsync()
{
var response = await Client.GetAsync("http://api.com/getJson");
dynamic obj = JsonConvert.DeserializeObject(await response.Content.ReadAsStringAsync());
return obj;
}
Run Code Online (Sandbox Code Playgroud)
选项 1:使用 Task.Run 并获取 task.Result。这解决了死锁问题,但它被迫在原始线程的同步上下文之外的新线程中运行。然而,在某些环境中这是非常不明智的:特别是 Web 应用程序。这是一个好的做法吗?
public void SyncMethod()
{
Task<decimal> task = Task.Run<decimal>(async () => await ProcessDataAsync());
var serviceResult = task.Result;
}
Run Code Online (Sandbox Code Playgroud)
Optoin 2:从 Sync …
我一直在思考我们在asp.net MVC中创建的视图模型对象的概念.我们的目的是实例化它并将其从控制器传递到视图并查看读取它并显示数据.
那些视图模型通常通过构造函数实例化.我们不需要初始化成员,我们可能不需要重新定义/覆盖无参数构造函数,我们不需要继承功能.
那么,为什么我们不使用struct类型作为视图模型而不是类.它将提高性能.
我正在使用 SQL Server 2008。
我有两张桌子
User( UserID, Name, Link)UserNotes( NoteID, UserID, Title, Description)这是示例数据结构。
INSERT INTO [User]
([UserID], [Name], [Link])
VALUES
(1, 'John', 'L1'),
(2, 'Steve', 'L234');
INSERT INTO [UserNotes]
([NoteID], [UserID], [Title], [Description])
VALUES
(1, 1, 'AboutJohn', 'This is about john'),
(2, 1, 'John Work', 'This is where John work'),
(3, 1, 'John Education', 'This is the uni where John go'),
(4, 2, 'Steve Note1', 'Des1 about Steve'),
(5, 2, 'Steve Note2', 'Des2 about …Run Code Online (Sandbox Code Playgroud) 我们想要做的是更改表格中行的背景颜色.每隔两行就会改变颜色.
Our id sequence is simple as follow:
id = 1,2,3,4,5,6,7,8,9,10,11,12,13,14,.....etc.
1,2 rows -> black
3,4 rows -> white
5,6 rows -> black
7,8 rows -> white
9,10 rows -> black
11,12 rows -> white
13,14 rows -> black
15,16 rows -> white
17,18 rows -> black
etc....
if(id==1) || (id==2) class="black";
if(id==3) || (id==4) class="white";
if(id==5) || (id==6) class="black";
if(id==7) || (id==8) class="white";
if(id==9) || (id==10) class="black";
if(id==11) || (id==12) class="white";
etc.....
Run Code Online (Sandbox Code Playgroud)
根据该id值,我们如何更改黑色或白色?
非常感谢.
我想知道我网站上的在线访客数量.我做了我的研究,发现了两个解决方案.
它易于设置且易于使用,但它也增加了每个Ajax请求/响应的用户数.仅我的主页有12个Ajax请求(对一个页面的8个请求和对另一个页面的4个请求).这大大增加了用户数量.
来源:Stack Overflow Q/A
计算访客数量
这个与前一个完全相同.
来源:ASP.Net论坛 如何使用C#查看"谁在线"
这个看起来比前两个好.以下是此解决方案的详细代码.
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
HttpContext.Current.Application["visitors_online"] = 0;
}
void Session_Start(object sender, EventArgs e)
{
Session.Timeout = 20; //'20 minute timeout
HttpContext.Current.Application.Lock();
Application["visitors_online"] = Convert.ToInt64(HttpContext.Current.Application["visitors_online"]) + 1;
HttpContext.Current.Application.UnLock();
}
void Session_End(object sender, EventArgs e)
{
HttpContext.Current.Application.Lock();
Application["visitors_online"] = Convert.ToInt64(HttpContext.Current.Application["visitors_online"]) - 1;
HttpContext.Current.Application.UnLock();
}
Run Code Online (Sandbox Code Playgroud)
它似乎能够忽略每个Ajax响应的计数增加,但它仍然会增加每个页面刷新或页面请求.
有没有办法计算ASP.Net中准确的在线访问者数量?
c# ×3
asp.net ×2
.net ×1
asp.net-mvc ×1
async-await ×1
asynchronous ×1
c#-2.0 ×1
c#-4.0 ×1
html ×1
javascript ×1
jquery ×1
math ×1
pivot ×1
pivot-table ×1
sql ×1