我正在開發(fā)一個(gè)由一些我實(shí)際上不認(rèn)識(shí)的人開發(fā)的項(xiàng)目。我在 POST 方法上遇到問題。該模型實(shí)際上是空的??雌饋砟P蜎]有填充在視圖上。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"); } }}這就是整個(gè)模型的定義。顯然是使用 MVC 的 ASP.NET Core。我注意到模型的大多數(shù)屬性在設(shè)置器上都是空的。
1 回答

Cats萌萌
TA貢獻(xiàn)1805條經(jīng)驗(yàn) 獲得超9個(gè)贊
在 cshtml 表單中,將 enctype 設(shè)置為“multipart/form-data”。否則文件將不會(huì)包含在您的模型中:
// 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 關(guān)注
- 149 瀏覽
添加回答
舉報(bào)
0/150
提交
取消