小编rhu*_*hes的帖子

发布多个复选框值的数组

为什么只有"db"复选框值数组的一个值被发送到服务器端脚本?

JQUERY:

$(".db").live("change", function() {
    $(this).add($(this).next("label")).add($(this).next().next("br")).remove().insertAfter(".db:last + label + br"); 
    var url = "myurl.php";
    var db = [];
    $.each($('.db:checked'), function() {
        db.push($(this).val()); 
    });
    if(db.length == 0) { 
        db = "none"; 
    }       
    $.post(url, {db: db}, function(response) {
        $("#dbdisplay").html(response); 
    });
    return true;
});
Run Code Online (Sandbox Code Playgroud)

HTML:

<input type="checkbox" name="db[]" class="db" value="track"/><label for="track">track</label></br>
<input type="checkbox" name="db[]" class="db" value="gps"/><label for="gps">gps</label></br>
<input type="checkbox" name="db[]" class="db" value="accounting"/><label for="accounting">accounting</label></br>
Run Code Online (Sandbox Code Playgroud)

编辑:我最后回答了我自己的问题,但有没有人有文件(或解释)为什么这是必要的?我很难找到确切的答案(因此是死后的帖子).

html php forms jquery post

8
推荐指数
3
解决办法
5万
查看次数

不像代码分析所描述的那样抛出和保留堆栈跟踪

做代码分析给了我CA2200项:

CA2200 Rethrow保留堆栈详细信息'func()'重新捕获捕获的异常并将其明确指定为参数.使用不带参数的'throw',以保留最初引发异常的堆栈位置.

我已经实现了这个建议,但无论如何我似乎都得到了相同的堆栈跟踪.

这是我的测试代码和输出(空格用于给出明显的行号):

第30行的预期错误

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace throw_test
{
    class Program
    {
        static void Main(string[] args)
        {

            try
            {
                try
                {


                    // line 22 below
                    throw new Exception();
                }
                catch (Exception ex) // DEFINES AND THROWS 'ex'
                {



                    // line 30 below
                    throw ex;
                }
            }
            catch (Exception ex)
            {
                Console.Write(ex.StackTrace);
            }

            Console.Read();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

产量

在c:\ Users\Richard\Documents\Visual Studio 2013\Projects\using_throw_closestream\using_throw_closestream\Program.cs中的throw_test.Program.Main(String [] args):第30行

第22行的预期错误

using System;
using …
Run Code Online (Sandbox Code Playgroud)

.net c# exception throw .net-4.5

8
推荐指数
2
解决办法
4415
查看次数

上传大文件(1GB)-ASP.net

我需要上传至少1GB文件大小的大文件.我正在使用ASP.Net,C#IIS 5.1作为我的开发平台.

我在用:

HIF.PostedFile.InputStream.Read(fileBytes,0,HIF.PostedFile.ContentLength)
Run Code Online (Sandbox Code Playgroud)

使用前:

File.WriteAllBytes(filePath, fileByteArray)
Run Code Online (Sandbox Code Playgroud)

(不会去这里,但给出System.OutOfMemoryException例外)

目前我已经设置httpRuntime为:

executionTimeout =" 999999 "maxRequestLength =" 2097151 "(多数2GB!)useFullyQualifiedRedirectUrl ="true"minFreeThreads ="8"minLocalRequestFreeThreads ="4"appRequestQueueLimit ="5000"enableVersionHeader ="true"requestLengthDiskThreshold ="8192"

我也设置了maxAllowedContentLength="**2097151**"(猜它只适用于IIS7)

我已将IIS连接超时更改为999,999秒.

我无法上传偶数文件4578KB(Ajaz-Uploader.zip)

.net c#

7
推荐指数
2
解决办法
5万
查看次数

Moq - 设置HttpResponse

我正在尝试使用MVC 4,Moq 4和C#4.5为ConrollerContext对象模拟HttpResponse

我的代码在这里:

var context = new Mock<HttpContextBase>();
var response = new Mock<HttpResponseBase>();

context.SetupProperty(c => c.Response = response);
Run Code Online (Sandbox Code Playgroud)

我已经尝试使用Setup().Returns()SetupGet(),但我不断收到以下错误:

"无法将属性或索引器'System.Web.HttpContextBase.Response'分配给 - 它是只读的.

我试过谷歌搜索并在这个网站上搜索,但我似乎无法找到答案.

c# asp.net-mvc unit-testing moq

7
推荐指数
2
解决办法
4256
查看次数

将'int'与'null'进行比较编译

可能重复:
C#可以将值类型与null进行比较

我刚刚在C#(4.0)编译器中遇到了一些奇怪的东西.

int x = 0;
if (x == null) // Only gives a warning - 'expression is always false'
    x = 1;

int y = (int)null; // Compile error
int z = (int)(int?)null; // Compiles, but runtime error 'Nullable object must have a value.'
Run Code Online (Sandbox Code Playgroud)

如果你不能分配nullint,为什么编译器允许你比较它们(它只给出一个警告)?

有趣的是,编译器不允许以下内容:

struct myStruct
{
};

myStruct s = new myStruct();
if (s == null) // does NOT compile
    ;
Run Code Online (Sandbox Code Playgroud)

为什么struct示例不能编译,但int示例呢?

c#

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

在Chrome DevTools网络面板中显示请求路径

我使用以下方式拨打以下电话jQuery:

$.ajax({
    url: "http://domain/..etc../calendars/",
// ...
});
Run Code Online (Sandbox Code Playgroud)

它返回我需要的结果.

我遇到的问题是这个调用在开发人员工具中表示如下:

在此输入图像描述

该呼叫只显示为:

?_=1443327272355
Run Code Online (Sandbox Code Playgroud)

这使得在没有过滤和搜索的情况下在所有其他呼叫中难以找到呼叫.

有没有办法可以显示呼叫至少:

/calendars/?_=1443327272355
Run Code Online (Sandbox Code Playgroud)

ajax jquery google-chrome-devtools

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

ubuntu 16 服务器上 Microsoft 软件包的哈希和不匹配

运行 apt update 时出现以下错误:

E: Failed to fetch https://packages.microsoft.com/ubuntu/16.04/prod/dists/xenial/main/binary-amd64/Packages.bz2 Hash Sum mismatch

E: Some index files failed to download. They have been ignored, or old ones used instead.

在有人认为这已经得到回答之前,我已经尝试了所有给出的解决方案,但没有一个奏效:我尝试过的解决方案:

#solution1
sudo rm -rf /var/lib/apt/lists/*
sudo apt-get update

#solution2
sudo apt-get clean
sudo apt-get update

#solution3
sudo rm -rf /var/lib/apt/lists/partial
sudo apt-get update -o Acquire::CompressionTypes::Order::=gz

#solution4
sudo sed -i -re 's/\w+\.archive\.ubuntu\.com/archive.ubuntu.com/g' /etc/apt/sources.list
Run Code Online (Sandbox Code Playgroud)

ubuntu apt package apt-get ubuntu-16.04

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

小写Boolean.ToString()值

我正在将a的值输出boolean到我的MVC视图中,并希望有一个小写true或者false,而不是默认值TrueFalse.

我很感激我可以这样做:

@this.Model.MyBool.ToString().ToLower()
Run Code Online (Sandbox Code Playgroud)

或使用某种扩展方法等...

但它有点挫败了以下目的:

@this.Model.MyBool
Run Code Online (Sandbox Code Playgroud)

我在这里读过这篇文章:为什么Boolean.ToString输出"True"而不是"true"但是大多数答案看起来都很旧.

有没有更现代的方法来做到这一点?

c# asp.net-mvc boolean tostring

6
推荐指数
3
解决办法
9179
查看次数

使用预处理程序生成默认值

我正在初始化一个包含数千个设置值的大型数组。我希望这些值在编译时设置,而不是在运行时设置,因为它们是固定的并且不会更改。

是否有可能使用预处理器自动生成这些值的方法?目前,我正在使用另一个小程序生成这些值,然后分别简单地复制和粘贴这些值。

这是我生成的:

class MyClass
{
public:
    MyClass(int x, int y, int z) : X(x), Y(y), Z(z) {}

    int X, Y, Z;
};

std::vector<MyClass> my_vector{
    #include "my_vector_default_values.h"
};
Run Code Online (Sandbox Code Playgroud)

my_vector_default_values.h

MyClass(0, 0, 1),
MyClass(0, 0, 2),
MyClass(0, 0, 3),
MyClass(0, 0, 4),
// etc... for thousands of lines
// ...
Run Code Online (Sandbox Code Playgroud)

编辑:

我生成的实际值生成如下(这是C#程序):

var sb = new StringBuilder();

var sizeX = 32;
var sizeY = 32;
var sizeZ = 32;

for (var x = 0; x < sizeX; x++)
{
    for (var …
Run Code Online (Sandbox Code Playgroud)

c++ c-preprocessor

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

在 Unity3d 中使用“record”类型时出现编译错误

我正在尝试使用recordUnity3d。文档说现在支持 C# 9,但我仍然收到错误:

\n
\n

必须定义或导入预定义类型“System.Runtime.CompilerServices.IsExternalInit”才能声明仅限 init 的 setter。

\n
\n

文档说明了这一点,但我不确定这意味着什么:

\n
\n

System.Runtime.CompilerServices.IsExternalInit 类型是完整记录支持所必需的,因为它仅使用 init setter,但仅在 .NET 5 及更高版本中可用(Unity 不\xe2\x80\x99t 支持)。用户可以通过在自己的项目中声明 System.Runtime.CompilerServices.IsExternalInit 类型来解决此问题。

\n
\n

c# unity-game-engine

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