小编Wim*_*ets的帖子

如何将JSON作为MVC 5操作方法参数接收

我整个下午都试图在网上爬行,试图在动作控制器中接收一个JSON对象.

这样做的正确和/或更简单的方法是什么?

我尝试过以下方法:1:

    //Post/ Roles/AddUser
    [HttpPost]
    public ActionResult AddUser(String model)
    {
        if(model != null)
        {
            return Json("Success");
        }else
        {
            return Json("An Error Has occoured");
        }

    }
Run Code Online (Sandbox Code Playgroud)

这给了我输入的空值.

2:

    //Post/ Roles/AddUser
    [HttpPost]
    public ActionResult AddUser(IDictionary<string, object> model)
    {
        if(model != null)
        {
            return Json("Success");
        }else
        {
            return Json("An Error Has occoured");
        }

    }
Run Code Online (Sandbox Code Playgroud)

这给了我jquery方面的500错误,试图发布到它?(意思是它没有正确绑定).

这是我的jQuery代码:

<script>
function submitForm() {

    var usersRoles = new Array;
    jQuery("#dualSelectRoles2 option").each(function () {
        usersRoles.push(jQuery(this).val());
    });
    console.log(usersRoles);

    jQuery.ajax({
        type: "POST",
        url: "@Url.Action("AddUser")",
        contentType: "application/json; charset=utf-8",
        dataType: "json", …
Run Code Online (Sandbox Code Playgroud)

asp.net asp.net-mvc json actionmethod

65
推荐指数
2
解决办法
19万
查看次数

cvc-complex-type.2.4.c:匹配的通配符是strict,但是没有为元素'context:property-placeholder'找到声明

任何人都可以帮助我解决以下错误,因为我刚开始春天?

cvc-complex-type.2.4.c: The matching wildcard is strict, but no         
declaration can be found for element 'context:property-placeholder'.
Run Code Online (Sandbox Code Playgroud)

我在applicationContext.xml中有以下配置:

<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans       
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"
xmlns:context="http://www.springframework.org/schema/context">

<bean id="dataSource"class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="${jdbc.driverClassName}"/>
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
</bean>
<context:property-placeholder location="src/jdbc.properties"/>
Run Code Online (Sandbox Code Playgroud)

spring

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

你为什么不能在$(this)上调用outerHTML?

当你想要得到的HTML整个DOM元素(包括包装),你可以做以下(如解释在这里):

$('#myElementId')[0].outerHTML
Run Code Online (Sandbox Code Playgroud)

但是,你不能做的是叫outerHTML$(this)内如点击收听或选择函数体范围:

$(this).outerHTML //Doesn't complete in IntelliSense, returns undefined in browser
Run Code Online (Sandbox Code Playgroud)

要么

$(this)[0].outerHTML //Correction, this DOES work, but it doesn't complete in IntelliSense
Run Code Online (Sandbox Code Playgroud)

因为IntelliSense不会显示innerHTMLouterHTML在这种情况下,尽管使用vanilla JavaScript,您可以执行以下操作:

document.getElementById($(this).attr('id')).outerHTML
Run Code Online (Sandbox Code Playgroud)

那么......那是什么呢?

javascript intellisense jquery javascript-intellisense visual-studio-2013

14
推荐指数
3
解决办法
3237
查看次数

SOAP请求转换错误

由于NDA我无法共享任何代码,所以希望有人可以在这里帮助我.

我正在尝试对客户端的后台进行SOAP调用,直到我要求结果为止.现在我的项目分为3个独立的项目文件

  • 主应用程序(netcoreapp1.0)
  • 型号(netcoreapp1.0)
  • 服务(netcoreapp1.0)

执行异步任务时,会发生以下错误.

System.String,System.Private.CoreLib,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = 7cec85d7bea7798e不能从System.String [],System.Private.CoreLib,Version = 4.0.0.0,Culture = neutral,PublicKeyToken分配= 7cec85d7bea7798e

关于这个调用我可以说的是我将一个字符串分配给一个包含一个属性(字符串)的类.所以我不确定这里有什么问题.

希望以前有人遇到过这个问题并且可以指出我的问题!

TX

soap .net-core

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

合并两个Collection <T>

我得到了一个返回a的函数,Collection<string>它以递归方式调用自身,最终返回一个大函数Collection<string>.

现在,我只是想知道合并列表的最佳方法是什么?Collection.CopyTo()只复制到string [],使用foreach()循环感觉效率低下.但是,因为我也想过滤掉重复的内容,我觉得我最终会得到一个调用Contains()它的foreach Collection.

我想知道,有一种更有效的方法来获得一个递归函数,它返回一个没有重复的字符串列表吗?我不必使用a Collection,它可以是几乎任何合适的数据类型.

只有排除,我绑定到Visual Studio 2005和.net 3.0,所以没有LINQ.

编辑:澄清:该功能将用户从Active Directory中取出,查看用户的直接报告,然后递归查看每个用户的直接报告.因此,最终结果是给定用户的"命令链"中的所有用户的列表.由于这是经常执行的,并且目前对于某些用户需要20秒,我正在寻找改进它的方法.将结果缓存24小时也在我的列表btw.,但我想看看如何在应用缓存之前改进它.

c# collections

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

.Net如何直接播放音频样本

我有通过NAudio提取的音频样本,我知道参数:

  • 渠道
  • 每个样本的字节数
  • 采样率

如何使用.Net api /或其他.Net库播放该示例

这里代码:

    openFileDialog1.ShowDialog();
    using (var reader = new Mp3FileReader(openFileDialog1.FileName))
    {
        var pcmLength = (int)reader.Length;
        var _leftBuffer = new byte[pcmLength / 2];
        var buffer = new byte[pcmLength];
        var bytesRead = reader.Read(buffer, 0, pcmLength);
        int index = 0;
        for (int i = 0; i < bytesRead; i += 4)
        {
           //extracting only left channel 
           _leftBuffer[index] = buffer[i];
           index++;
           _leftBuffer[index] = buffer[i + 1];
           index++;
         }

         // How to play  _leftBuffer (Single channel, 2 bytes per sample, …
Run Code Online (Sandbox Code Playgroud)

.net c# audio naudio

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

无法访问该文件,因为它正由另一个进程使用

我的web方法在我的%temp%文件夹中创建一个pdf文件,该文件有效.然后,我想使用下面的代码向该文件添加一些自定义字段(meta).

该类PdfStamper生成一个IOException,无论我使用它的.Close()方法还是using块刚结束.仍然保留文件句柄的过程是webdev Web服务器本身(我在VS2010 SP1中进行调试).

private string AddCustomMetaData(string guid, int companyID, string filePath)
{
    try
    {
        PdfReader reader = new PdfReader(filePath);

        using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite))
        {
            PdfStamper st = new PdfStamper(reader, fs);
            Dictionary<string, string> info = reader.Info;
            info.Add("Guid", guid);
            info.Add("CompanyID", companyID.ToString());

            st.MoreInfo = info;
            st.Close();
        }

        reader.Close();

        return guid;
    }
    catch (Exception e)
    {
        return e.Message;
    }
}
Run Code Online (Sandbox Code Playgroud)

无论我尝试什么,它都会不断抛出异常st.Close();,更确切地说:

该进程无法访问文件'C:\ Users [我的用户名]\AppData\Local\Temp\53b96eaf-74a6-49d7-a715-6c2e866a63c3.pdf',因为它正由另一个进程使用.

要么我忽视了一些显而易见的事情,要么就是PdfStamper我还没有意识到的课程有问题.使用的itextsharp的版本是5.3.3.0和5.4.0.0,问题是相同的.

任何见解将不胜感激. …

c# asp.net itextsharp pdfstamper

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

ef core 多次附加同一实体

我确定之前有人问过这个问题,我不知道要搜索什么,所以它可能是重复的。我有将新实体添加到数据库的代码。该实体引用了另一个实体(Role),我通过服务获取它。服务创建了另一个实例dbContext,因此我必须在获取角色后将其附加到上下文。问题是,当我尝试附加两个相同的角色时,出现以下异常:

无法跟踪“角色”,因为已跟踪具有相同 {'Id'} 键值的另一个实例。附加现有实体时,请确保仅附加一个具有给定键值的实体实例。考虑使用“DbContextOptionsBuilder.EnableSensitiveDataLogging”来查看冲突的键值。

我该怎么做呢?代码如下:

using (var context = new TenantContext(schemaName, connectionString))
{
    ApprovalTemplates templates = new ApprovalTemplates();
    ApprovalTemplate template = new ApprovalTemplate();
    template.Approvers = new List<StageTemplate>();

    foreach (var stage in request.Stages)
    {
        var temp = new StageTemplate();
        temp.Order = stage.Order;
        temp.Name = stage.Name;
        var role = roleService.GetById(stage.RoleId, schemaName);//here I get the role
        temp.AvailableActions = new List<ApprovalActionTemplate>();

        foreach (var actionId in stage.Actions)
            temp.AvailableActions.Add(context.ApprovalActions.First(a => a.Id == actionId));

        //when I try to add already attached role, exception …
Run Code Online (Sandbox Code Playgroud)

c# entity-framework-core

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

如何使用 C# 从 XML Web 服务获取值?

在 C# 中,如果我需要打开 HTTP 连接、下载 XML 并从结果中获取一个值,我该怎么做?

为了保持一致性,假设 Web 服务位于 www.webservice.com,并且如果您向它传递 POST 参数 fXML=1,它会返回给您

<xml><somekey>somevalue</somekey></xml>
Run Code Online (Sandbox Code Playgroud)

我希望它能吐出“somevalue”。

c# xml web-services

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

将动态控件插入控件集合的中间

这是我的第一篇文章!我非常绝望,所以我超越了标准的谷歌搜索.我相信这是一个高级或专家级的.NET问题.

问题是我构建了一个.NET Web应用程序,它需要能够动态地将用户控件插入到列表中间.我对动态控件非常熟悉这么长时间他们只需要添加到列表的末尾(即:我熟悉这样的文章:http://msdn.microsoft.com/en-us/library/ ms972976.aspx).但是,如果我需要将一个UserControl添加到Controls集合的前面或中间的某个地方,那么由于控件的UniqueID被抛弃,我几乎丢失了.

作为一个简化的例子,假设我有一个Panel,我正在添加一个名为MyControl.ascx的UserControl列表.我还有一些事件可以在页面上触发,需要动态地将MyControl.ascx插入到面板的Controls集合的指定索引中.我还需要在MyControl.ascx上有一个或多个事件我需要订阅.这意味着需要在这些控件上的事件触发之前加载控件,否则它们将不会触发.如果你不知道我所指的是什么,那么我要么说问题不好,要么这个问题可能对你来说太难了:)

下面是一些C#伪代码来演示这个问题.问题是Controls.AddAt(索引,控制)方法不会相应地调整控件的UniqueID值.例如,请考虑Controls集合中的以下控件:

无论我是否实际编写直接依赖于UniqueID的代码,.NET间接使用UniqueID将在先前回发上触发的事件链接在一起,并在新的回发上加载控件.以前面的例子为例:

在最初 Page Load (Page.IsPostback == false)

<table>
  <tr>
    <td width='100'>Control index</td>
    <td width='75'>UniqueID</td>
    <td>Value</td>
  </tr>
  <tr>
    <td>0</td>
    <td>ctl00</td>
    <td>value1</td>
  </tr>
  <tr>
    <td>1</td>
    <td>ctl01</td>
    <td>value2</td>
  </tr>
  <tr>
    <td>2</td>
    <td>ctl02</td>
    <td>value3</td>
  </tr>
</table>
Run Code Online (Sandbox Code Playgroud)

Page.IsPostback == false某个其他控件想要在索引0处插入控件的回发()之后:

如果我这样做,Controls.AddAt(0, newControl)那么Controls集合看起来像这样:

<table>
  <tr>
    <td width='100'>Control index</td>
    <td width='75'>UniqueID</td>
    <td>Value</td>
  </tr>
  <tr>
    <td>0</td>
    <td>ctl03</td>
    <td>value0  <== the controls' unique IDs do not shift!</td>
  </tr>
  <tr>
    <td>1</td>
    <td>ctl00</td>
    <td>value1</td>
  </tr>
  <tr>
    <td>2</td> …
Run Code Online (Sandbox Code Playgroud)

c# asp.net user-controls dynamic-controls

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