小编ZiN*_*NED的帖子

对于物理上不同的文件中的控制器,Ajax调用较慢

在尝试加速我们的一个MVC页面中的一些ajax调用时,我遇到了一些我无法解释的奇怪行为.我每隔N秒就有一些ajax调用用于轮询一些统计信息.

似乎对物理上不同的文件中的控制器进行的ajax调用比对视图源自的同一物理文件中的控制器进行的类似调用要慢得多.

看我简化的例子:

情况1:只有1个文件

FooController.cs

namespace FooBar.Areas.FooArea.Controllers
{
    [SessionState(System.Web.SessionState.SessionStateBehavior.ReadOnly)]
    public class FooTestController: _BaseController
    {
        public JsonResult GetStats()
        {
            try
            {
                var req = new RestRequest() { Method = Method.GET };
                req.AddHeader("Content-Type", "application/json");
                req.AddHeader("Accept", "application/json");
                req.AddParameter("apikey", /*APIKEY*/);

                var client = new RestClient(/*STATSURL*/);
                var response = client.Execute(req);

                if (response.StatusCode == HttpStatusCode.OK)
                    return Json(new { success = true, content = response.Content });
                else
                    return Json(new { success = false });
            }
            catch
            {
                return Json(new { success = false });
            }
        }

        public …
Run Code Online (Sandbox Code Playgroud)

c# ajax asp.net-mvc

6
推荐指数
1
解决办法
255
查看次数

使用javascript基于另一个数组对一个数组进行排序

我有两个数组

  1. MRP [60 80 82 50 80 80 ]
  2. [ A B C D E F ]

我需要根据MRP获得两大品牌.MRP中最高的两个是82,80但80是重复的3次所以我需要所有重复的值以获得前两个品牌.即我需要显示[C B E F]

为此我按降序排序MRP.现在排序后的MRP变为 [ 82 80 80 60 50 ]

现在我需要根据Sorted MRP对Brand Array进行排序.可以使用javascript对这个排序中的一些帮助.

javascript java arrays sorting jquery

3
推荐指数
1
解决办法
1886
查看次数

C# 中的 Google.Protobuff timestamp.proto

我已经使用 google.proto.Timestamp 成功编译了我的 .proto 文件,并使用 protoc 生成了 .cs 文件。我遇到的唯一问题是在我的 c# 代码中初始化。

我尝试了以下方法:

.proto 文件

message teststamp
{
    string Name = 1 ;
    string address = 2;
    google.protobuf.Timestamp _timeStamp = 3;
}
Run Code Online (Sandbox Code Playgroud)

C#文件

teststamp test = new teststamp();
test.Name = "Test";
test.address = "Test_Test_TEST"
//Example 2 : POSIX
test._timeStamp.Seconds = DateTime.Now.Second;
test._timeStamp.Nanos = DateTime.Now.Second*1000 ;
Run Code Online (Sandbox Code Playgroud)

上面的编译没有错误,但给了我这个错误:Object reference not set to an instance of an object.我尝试了一些其他方法,但由于帮助较少,它无法修复错误。

请帮我解决这个问题

谢谢

c# protocol-buffers

3
推荐指数
4
解决办法
1万
查看次数

Visual Studio 2019 project upgrade to C#8 build failed

For one of our projects we're trying to upgrade to use C#8 instead of C#7.1. The upgrade looks like it works, because the compiler looks like it takes C#8 statements (it doesn't mark it as an error). However, when I build the project I get a build failed without any errors showing initially.

The code to test C#8 is of the following lines:

private string TestCSharp8(int x)
{
    return x switch
    {
        0 => "ZERO",
        1 => "ONE",
        2 => …
Run Code Online (Sandbox Code Playgroud)

c# c#-8.0 visual-studio-2019

1
推荐指数
1
解决办法
924
查看次数

使用泛型类作为非泛型类C#的属性

说我有以下两个类,理想情况下做我想要的:

Foo.cs:

public class Foo
{
    private int Type { get; set; } = 0;

    public FooHelper FooHelper
    {
        get
        {
            switch (Type)
            {
                case 1:
                    return new FooHelper<Guid>("Foo", "Bar", "foobar", "", Guid.NewGuid());
                case 2:
                default:
                    return new FooHelper<int>("Bar", "Foo", "", "", 11);
            }
        }
    }

    public Foo(int type)
    {
        Type = type;
    }
}
Run Code Online (Sandbox Code Playgroud)

FooHelper.cs:

public class FooHelper<T> where T : struct
{
    public string Controller { get; set; }    = string.Empty;
    public string Action { get; set; } …
Run Code Online (Sandbox Code Playgroud)

c# generics

0
推荐指数
1
解决办法
510
查看次数