亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

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 關注
  • 141 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號