我正在開發一個由一些我實際上不認識的人開發的項目。我在 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" }))
- 1 回答
- 0 關注
- 141 瀏覽
添加回答
舉報
0/150
提交
取消