小编Jos*_*Son的帖子

HttpPostedFileBase始终在ASP.NET MVC中返回null

我在ASP.NET MVC中上传文件时遇到问题.我的代码如下:

视图:

@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>Index2</h2>
@using (Html.BeginForm("FileUpload", "Board", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
  <input type="file" />
  <input type="submit" />
}
Run Code Online (Sandbox Code Playgroud)

控制器:

[HttpPost]
public ActionResult FileUpload(HttpPostedFileBase uploadFile)
{
    if (uploadFile != null && uploadFile.ContentLength > 0)
    {
        string filePath = Path.Combine(Server.MapPath("/Temp"), Path.GetFileName(uploadFile.FileName));
        uploadFile.SaveAs(filePath);
    }
    return View();
}
Run Code Online (Sandbox Code Playgroud)

但uploadFile总是返回null.任何人都可以找出原因??

asp.net-mvc file-upload

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

如何在C#中将参数传递给线程

所有我都搜索过这个问题,我找到了很多答案并不难找到我的问题的解决方案.但是,我有奇怪的经历,我不知道这就是为什么我要求别人给我一些建议的原因.这是我的代码:

    void SetThread()
    {
        for (int i = 0; i < _intArrayLength; i++)
        {
            Console.Write(string.Format("SetThread->i: {0}\r\n", i));
            _th[i] = new Thread(new ThreadStart(() => RunThread(i)));
            _th[i].Start();
        }
    }

    void RunThread(int num)
    {
        Console.Write(string.Format("RunThread->num: {0}\r\n", num));
    }
Run Code Online (Sandbox Code Playgroud)

是的,它们是普通的线程代码.我希望所有的线程数组都应该调用RunThread方法10次.应该是这样的

SetThread->i: 0
SetThread->i: 1
SetThread->i: 2
SetThread->i: 3
SetThread->i: 4
SetThread->i: 5
SetThread->i: 6
SetThread->i: 7
SetThread->i: 8
SetThread->i: 9
RunThread->num: 0
RunThread->num: 1
RunThread->num: 2
RunThread->num: 3
RunThread->num: 4
RunThread->num: 5
RunThread->num: 6
RunThread->num: 7
RunThread->num: 8
RunThread->num: 9
Run Code Online (Sandbox Code Playgroud)

这就是我期望的.订单并不重要.但我得到的结果如下.

SetThread->i: 0
SetThread->i: …
Run Code Online (Sandbox Code Playgroud)

c# multithreading

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

Apple Mach-O链接器(id)错误

我有一个错误如下:

ld /Volumes/Data/Library/Developer/Xcode/DerivedData/uniText-cgynaitlevdrajfeoaldwldehaft/Build/Products/Debug-iphonesimulator/uniText.app/uniText normal i386
    cd "/Volumes/Data/Documents/XCode Projects/Trans SMS"
    setenv MACOSX_DEPLOYMENT_TARGET 10.6
    setenv PATH "/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
    /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/llvm-gcc-4.2 -arch i386 -isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.3.sdk -L/Volumes/Data/Library/Developer/Xcode/DerivedData/uniText-cgynaitlevdrajfeoaldwldehaft/Build/Products/Debug-iphonesimulator -F/Volumes/Data/Library/Developer/Xcode/DerivedData/uniText-cgynaitlevdrajfeoaldwldehaft/Build/Products/Debug-iphonesimulator -filelist /Volumes/Data/Library/Developer/Xcode/DerivedData/uniText-cgynaitlevdrajfeoaldwldehaft/Build/Intermediates/uniText.build/Debug-iphonesimulator/uniText.build/Objects-normal/i386/uniText.LinkFileList -mmacosx-version-min=10.6 -Xlinker -objc_abi_version -Xlinker 2 -framework SystemConfiguration -framework MessageUI -framework AddressBook -framework AddressBookUI -framework CoreTelephony -lsqlite3.0 -framework UIKit -framework Foundation -framework CoreGraphics -o /Volumes/Data/Library/Developer/Xcode/DerivedData/uniText-cgynaitlevdrajfeoaldwldehaft/Build/Products/Debug-iphonesimulator/uniText.app/uniText

ld: duplicate symbol _OBJC_IVAR_$_FMDatabase.databasePath in /Volumes/Data/Library/Developer/Xcode/DerivedData/uniText-cgynaitlevdrajfeoaldwldehaft/Build/Intermediates/uniText.build/Debug-iphonesimulator/uniText.build/Objects-normal/i386/FMDatabase-566DC6D59187887D.o and /Volumes/Data/Library/Developer/Xcode/DerivedData/uniText-cgynaitlevdrajfeoaldwldehaft/Build/Intermediates/uniText.build/Debug-iphonesimulator/uniText.build/Objects-normal/i386/FMDatabase-566DC6D59187887D.o for architecture i386
collect2: ld returned 1 exit status
Command /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/llvm-gcc-4.2 failed with exit code 1
Run Code Online (Sandbox Code Playgroud)

有人可以帮帮我吗?以前它曾经正常工作.我不知道我在项目来源中发生了什么变化.但我确信我从未改变过FMDatabase.h和.m中的任何内容.

ios xcode4

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

我怎么知道C#中BinaryReader的当前偏移量?

我有以下来源:

public static void DisplayValues()
{
    float aspectRatio;
    string tempDirectory;
    int autoSaveTime;
    bool showStatusBar;

    if (File.Exists(fileName))
    {
        using (BinaryReader reader = new BinaryReader(File.Open(fileName, FileMode.Open)))
        {
            aspectRatio = reader.ReadSingle();
            tempDirectory = reader.ReadString();
    ------------------------------------------------> I want to know current offset.
            autoSaveTime = reader.ReadInt32();
            showStatusBar = reader.ReadBoolean();
        }

        Console.WriteLine("Aspect ratio set to: " + aspectRatio);
        Console.WriteLine("Temp directory is: " + tempDirectory);
        Console.WriteLine("Auto save time set to: " + autoSaveTime);
        Console.WriteLine("Show status bar: " + showStatusBar);
    }
}
Run Code Online (Sandbox Code Playgroud)

我必须找出BinaryReader的当前偏移量.

c# binaryreader

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

如何在c#中使用逗号将数组连接到字符串

假设我有一个数组.

string[] temp = { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j" };
Run Code Online (Sandbox Code Playgroud)

我想用逗号来加入他们,每个项目如下所示.

string[] temp2 = { "a,b,c", "d,e,f", "g,h,i", "j" };
Run Code Online (Sandbox Code Playgroud)

我知道我可以使用

string temp3 = string.Join(",", temp);
Run Code Online (Sandbox Code Playgroud)

但这给了我结果

"a,b,c,d,e,f,g,h,i,j"
Run Code Online (Sandbox Code Playgroud)

有没有人有想法?

c# arrays string

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

如何使用jQuery克隆表中的两列

我试图使用jQuery从表中克隆2列到新表.源表如下:

<table id="sourceT">
    <tr>
        <td>Col 1</td>
        <td>Col 2</td>
        <td>Col 3</td>
    </tr>
    <tr>
        <td>Col 1 - value</td>
        <td>Col 2 - value</td>
        <td>Col 3 - value</td>
    </tr>
</table>
<table id="targetT"></table>
Run Code Online (Sandbox Code Playgroud)

我试过的是,

$("#sourceT").find("tr > td:nth-child(1), tr > td:nth-child(2)").each(function () {
    $("#targetT").append($("<tr></tr>").append($(this).clone()));
});
Run Code Online (Sandbox Code Playgroud)

我只想将第一列和第二列复制到新表中

<table id="targetT">
    <tr>
        <td>Col 1</td>
        <td>Col 2</td>
   </tr>
    <tr>
        <td>Col 1 - value</td>
        <td>Col 2 - value</td>
   </tr>
</table>
Run Code Online (Sandbox Code Playgroud)

但是使用那些jquery,我只能得到如下;

<table id="targetT">
    <tr>
        <td>Col 1</td>
    </td>
    <tr>
        <td>Col 1 - value</td>
    </td>
    <tr>
        <td>Col 2</td>
    </td>
    <tr>
        <td>Col 2 - …
Run Code Online (Sandbox Code Playgroud)

jquery clone html-table

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

如何取消winform按钮点击事件?

我有一个从System.Windows.Forms.Button继承的自定义按钮类.

我想在winform项目中使用这个按钮.

此类称为"ConfirmButton",它显示带有"是"或"否"的确认消息.

但问题是,当用户选择否带有确认消息时,我不知道如何停止点击事件.

这是我的班级来源.

using System;
using System.ComponentModel;
using System.Windows.Forms;

namespace ConfirmControlTest
{
    public partial class ConfirmButton : System.Windows.Forms.Button
    {
        public Button()
        {
            InitializeComponent();

            this.Click  += Button_Click;
        }

        void Button_Click(object sender, EventArgs e)
        {
            DialogResult res    = MessageBox.Show("Would you like to run the command?"
                , "Confirm"
                , MessageBoxButtons.YesNo
                );
            if (res == System.Windows.Forms.DialogResult.No)
            {
                // I have to cancel button click event here

            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

如果用户从确认消息中选择"否",则不再触发按钮单击事件.

c# click onclick button

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

app.config 中的自定义部分在 C# 中引发错误

// WinConfiguration.cs

using System;
using System.Configuration;

namespace BANANA.Common
{
    public class WinConfiguration : ConfigurationSection
    {
        public readonly static BANANA.Common.WinConfiguration Settings
            = (BANANA.Common.WinConfiguration)System.Configuration.ConfigurationManager.GetSection("BANANA");

        [ConfigurationProperty("connections")]
        public ConnectionsCollection Connections
        {
            get { return (ConnectionsCollection)this["connections"]; }
        }

        [ConfigurationProperty("cryptography")]
        public CryptographyCollection Cryptography
        {
            get { return (CryptographyCollection)this["cryptography"]; }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

// app.config

<?xml version="1.0"?>
<configuration>
    <configSections>
        <section name="BANANA" type="BANANA.Common.WinConfiguration"/>
    </configSections>
    <BANANA>
        <connections>
            <add name="SqlServer2008" connectionString="" providerName="System.Data.SqlClient" priority="100" />
        </connections>
        <cryptography>
            <add type="DES" value="12345" />
            <add type="TripleDES" value="12345" />
        </cryptography>
    </BANANA>
    <startup>
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/> …
Run Code Online (Sandbox Code Playgroud)

c# configuration

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

如何从 html 中删除特定标签

可能的重复:
如何使用 HTML Agility 包

我有下面的html代码:

<div><span class="help">This is text.</span>Hello, this is text.</div>
<div>I have a question.<span class="help">Hi</span></div>
Run Code Online (Sandbox Code Playgroud)

现在,我想删除<span class="help"></span>使用 C#之间的文本。所以,我只想离开

<div>Hello, this is text.</div>
<div>I have a question.</div>
Run Code Online (Sandbox Code Playgroud)

任何人有任何想法?

html c#

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