为了账号安全,请及时绑定邮箱和手机立即绑定

POST 上的模型为空

POST 上的模型为空

C#
撒科打诨 2023-07-09 17:33:08
我正在开发一个由一些我实际上不认识的人开发的项目。我在 POST 方法上遇到问题。该模型实际上是空的。看起来模型没有填充在视图上。public ActionResult ConfermaRistampa(int IDTitolo, Ristampa ristampa) //Ristampa is the model{    //some code    if (ristampa.RichiestaRistampaWeb != null) //the field "RichiestaRistampaWeb" is null    {        ristampa.RichiestaRistampa = Utilities.ConverteFileInToFileUploadInfo(ristampa.RichiestaRistampaWeb, TipiDocumenti.Documento_Generico);    }}//this is the code of field on the Ristampa class declaration, in the set i noticed that value is nullpublic System.Web.HttpPostedFileBase RichiestaRistampaWeb{    get    {        return this.RichiestaRistampaWebField;    }    set    {        if ((object.ReferenceEquals(this.RichiestaRistampaWebField, value) != true))        {            this.RichiestaRistampaWebField = value;            this.RaisePropertyChanged("RichiestaRistampaWeb");        }    }}这就是整个模型的定义。显然是使用 MVC 的 ASP.NET Core。我注意到模型的大多数属性在设置器上都是空的。
查看完整描述

1 回答

?
Cats萌萌

TA贡献1805条经验 获得超9个赞

在 cshtml 表单中,将 enctype 设置为“multipart/form-data”。否则文件将不会包含在您的模型中:


// Magic all the way to the right -->

@using (Html.BeginForm("ConfermaRistampa", "Abbonamenti", new { @IDTitolo = Request.QueryString["IDTitolo"] }, FormMethod.Post, new { enctype="multipart/form-data" }))



查看完整回答
反对 回复 2023-07-09
  • 1 回答
  • 0 关注
  • 121 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信