将模型类的列表从视图传递到Asp.NetCore中的控制器

问题描述 投票:0回答:1

我当前正在尝试将ModelClass(FileInfo)的列表发布到我的控制器,但是提交似乎根本没有调用该控制器,即使在调试时,该过程也没有进入我的Controller Action,以下是我的查看代码(claimdocumentform.cshtml),

@model IList<PIBSSBus.DomainModels.FileInfo>


 <form method="POST" enctype="multipart/form-data">

          <table class="table table-striped table-hover table-bordered" id="sample_editable_1">

                                       <thead>

                                            <tr>

                                                <th> Document</th>

                                                <th> Submitted </th>

                                                <th> Date Submitted </th>

                                                <th> # </th>
                                            </tr>
                                        </thead>
                                        <tbody>

                                            <tr>
                                                <td> <input type="text" placeholder="title" asp-for="@Model[0].Title" value="enter">  </td>
                                                <td><input type="text" placeholder="Description" asp-for="@Model[0].Description" value="enter1"> </td>
                                                <td>  </td>

                                                <td>
                                                    <input type="file" class="" asp-for="@Model[0].File"  value="Upload">
                                                </td>
                                            </tr> 
                                            <tr>
                                                <td> <input type="text" placeholder="title" asp-for="@Model[1].Title" value="enter2"> </td>
                                                <td><input type="text" placeholder="Description" asp-for="@Model[1].Description" value="enter3"> </td>
                                                <td>  </td>

                                                <td>
                                                    <input type="file" class="" asp-for="@Model[1].File" value="Upload">
                                                </td>
                                            </tr> 

                                           @* @Html.AntiForgeryToken();*@
                                        </tbody>
                                    </table>'
<button type="submit" asp-controller="Claims" asp-action="Wazobia" class="btn green button-submit">
    Submit
    <i class="fa fa-check"></i>
</button>
</form>

这是我的控制器

 public IActionResult claimdocumentform()
    {
        //PIBSSBus.DomainModels.FileInfo something = new PIBSSBus.DomainModels.FileInfo();
       // IList<PIBSSBus.DomainModels.FileInfo> filess =new List<PIBSSBus.DomainModels.FileInfo>();
        return View();
    }
  //  [ValidateAntiForgeryToken]
    [HttpPost]
    public IActionResult Wazobia(IList<PIBSSBus.DomainModels.FileInfo> fam)
    {

        return View();
    }

这是我的模特班

public class FileInfo
{

    public string Title { get; set; }


    public string Description { get; set; }


    [DataType(DataType.Upload)]
    public IFormFile File { get; set; }
}

这个问题我试图将包含两行的FileInfo类的列表传递给我的控制器动作Wazobia,但它根本不调用该动作,请帮助

asp.net-core-2.2
1个回答
0
投票

我首先在asp.net core 3.0中测试了代码,并且效果很好(您也可以尝试一下)。然后,我尝试在asp.net core 2.2 MVC中运行,但它不像您那样运行。

© www.soinside.com 2019 - 2024. All rights reserved.