小编Moe*_*eck的帖子

下拉列表检查索引是否由代码或选择更改

我有DropDownList一个项目.这DropDownList包含一个SelectedIndexChanged事件:

private void cbo_SelectedIndexChanged(object sender, EventArgs e){......}
Run Code Online (Sandbox Code Playgroud)

是否可以检查代码中的索引是否已更改,例如:

cbo.SelectedIndex = placering;
Run Code Online (Sandbox Code Playgroud)

,或者如果用户交互发生了变化?

c# winforms

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

字节串到字节数组c#

在我的Web应用程序中,我连接到Web服务.在我的Web服务中,它有一个根据路径获取报告字节的方​​法:

public byte[] GetDocument(string path)
{
   byte[] bytes = System.IO.File.ReadAllBytes(path);
   return bytes;
}
Run Code Online (Sandbox Code Playgroud)

现在,当我从我的Web应用程序发出请求时,Web服务给了我一个Json对象,类似于:

{
  "Report":"0M8R4KGxGuEAAAAAAAAAAAAAAAAAAAAAPgADAP7/CQAGAAAAAAAAAAAA
   AAACAAAA3QAAAAAAAAAAEAAA3wAAAAEAAAD+ ... (continues)" 
}
Run Code Online (Sandbox Code Playgroud)

在我的Web应用程序中,我有一个获取Json对象的方法,将"report"放在一个字符串中.然后,Web应用程序有一个方法将字符串解析为字节数组,这不起作用,它抛出一个FormatException:

public byte[] DownloadReport(string id, string fileName)
{
    var fileAsString = _api.DownloadReport(id, fileName);
    byte[] report = fileAsString.Split()
                                .Select(t => byte.Parse(t, NumberStyles.AllowHexSpecifier))
                                .ToArray();
    return report;
}
Run Code Online (Sandbox Code Playgroud)

我也试过这样做:

public byte[] DownloadReport(string id, string fileName)
{
   var fileAsString = _api.DownloadReport(id, fileName);
   byte[] report = Encoding.ASCII.GetBytes(fileAsString);
   return report;
}
Run Code Online (Sandbox Code Playgroud)

这给了我一个.doc文件,其中包含与Json对象完全相同的字符串.

我是从Web服务解析错误的方法,还是我想再次将其转换为字节数组?

c# byte json

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

外部JavaScript不起作用,而内部则起作用

我有mvc4网页,我有一个 @Html.TextBox()

@Html.TextBox("searchString", null, new { id = "searchingForProject" })     
Run Code Online (Sandbox Code Playgroud)

此文本框具有一个keyup侦听器,它将启动项目的ajax搜索,并在结果成功时更新视图

var timeoutReference;
var timeoutforloading;
$(function () {

   $("#searchingForProject").keyup(function () {
        timeoutReference = setTimeout(function () {
            timeoutforloading = setTimeout(function () {
                $("#imageWebGridLoad").show();
                $("#gridcontent").hide();
            }, 250);

            var value = $("#searchingForProject").val();
            $.ajax({
                url: '@Url.Action("Index", "Project")',
                contentType: 'application/html; charset=utf-8',
                type: "GET",
                dataType: 'html',
                data: { searchString: value },
            }).success(function (result) {

                $('projects').html(result);
                clearTimeout(timeoutforloading);
            });
        }, 750);
    });
});
Run Code Online (Sandbox Code Playgroud)

问题是,这个函数工作得很好,如果它放在一个内部<script>,但如果它被放在一个外部的javascript文件中,它将不会给我任何结果.

我知道它会调用该函数,因为$("#imageWebGridLoad").show();它将在0.25秒后开始旋转.

这是我的Ajax调用中的错误,还是不可能在这样的外部js文件中执行?

asp.net-mvc jquery

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

标签 统计

c# ×2

asp.net-mvc ×1

byte ×1

jquery ×1

json ×1

winforms ×1