Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何将复选框ID与IEnumerable中的文件匹配<;HttpPostedFileBase>;_C#_Html_Httppostedfilebase - Fatal编程技术网

C# 如何将复选框ID与IEnumerable中的文件匹配<;HttpPostedFileBase>;

C# 如何将复选框ID与IEnumerable中的文件匹配<;HttpPostedFileBase>;,c#,html,httppostedfilebase,C#,Html,Httppostedfilebase,我创建了一个模型,在该模型中,用户可以选择状态的复选框,并上传选定状态的文件。对于每个状态,都有一个使用(input type=“file”)属性创建的上载按钮,因此Html.BeginForm会发送所有HttpPostedFileBase对象,即使这些对象不是由用户创建的。 问题是,我无法匹配状态和上载的文件。 有没有一种方法可以让它们在服务器端或前端匹配 @使用(Html.BeginForm(“ResaleCertificateUpload”、“CustomerLookup”、FormM

我创建了一个模型,在该模型中,用户可以选择状态的复选框,并上传选定状态的文件。对于每个状态,都有一个使用(input type=“file”)属性创建的上载按钮,因此Html.BeginForm会发送所有HttpPostedFileBase对象,即使这些对象不是由用户创建的。 问题是,我无法匹配状态和上载的文件。 有没有一种方法可以让它们在服务器端或前端匹配

@使用(Html.BeginForm(“ResaleCertificateUpload”、“CustomerLookup”、FormMethod.Post、new{enctype=“multipart/form data”}))
{
@对于(int i=0;i<@Model.US_States.Length;i++)
{
如果(0==i%3)
{
}
int index=i/3+(i%3)*((@Model.US_States.Length+1)/3);//订单状态
@{ 
字符串stateCheckboxId=“state+”+Model.US_States[index]。缩写;
}
@Model.US_States[index].ToString()
}

查看此答案-它完全符合您的要求:)
@using (Html.BeginForm("ResaleCertificateUpload", "CustomerLookup", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<div class="row" id="usStates">
    <div class="col-xs-12">
        @for (int i = 0; i < @Model.US_States.Length; i++)
        {

            if (0 == i % 3)
            {
                <div id="taxCertificateRow" + @i.ToString() class="row"></div>
            }

            int index = i / 3 + (i % 3) * ((@Model.US_States.Length + 1) / 3); //Order states 
            <div class="col-xs-4">
                <label>
                    @{ 
                        string stateCheckboxId = "state+" + Model.US_States[index].Abbreviations;
                    }
                    <!--do the same for CA-->
                    <input type="checkbox" class="checkboxState" id='@stateCheckboxId' name="states" value="@Model.US_States[index].Name" onclick="stateCheckboxClicked('@stateCheckboxId', 'file+@Model.US_States[index].Abbreviations')">
                    <span>@Model.US_States[index].ToString() &nbsp;</span>
                </label>
                <input type="file" name="passedInFiles" id="file+@Model.US_States[index].Abbreviations" style="display:none" />
            </div>
}