POST 上的模型为空

我正在开发一个由一些我实际上不认识的人开发的项目。我在 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 null

public 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。我注意到模型的大多数属性在设置器上都是空的。


撒科打诨
浏览 122回答 1
1回答

Cats萌萌

在 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" }))
打开App,查看更多内容
随时随地看视频慕课网APP