私はMVCとWebプログラミングが初めてです。イメージのHttpPostedFileBaseをアップロードしますが、常にnullです
私のアップロードイメージはうまくいきますが、ほぼ同じコードを使用してアップロードを変更できるようにすると、HttpPostedFileBaseは常にnullになります。私を夢中にする...
ここにモデルです パブリッククラスModifyGenreViewModel { public int Id {get;セット; }
[Display(Name = "Nom du style")]
public string Name { get; set; }
[Display(Name = "Image")]
public HttpPostedFileBase Image { get; set; }
}
とビュー
@using (Html.BeginForm("ModifyGenre", "Upload", null, FormMethod.Post, new { enctype = "multipart/form-data" }))
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>@Resource.StyleCreationHeader</h4>
<hr />
@Html.ValidationMessageFor(model=>Model)
<div class="form-group" style="display:none">
@Html.LabelFor(model => model.Id, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-5">
@Html.EditorFor(model => model.Id, new { htmlAttributes = new { @class = "form-control" } })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Name, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-5">
@Html.EditorFor(model => model.Name, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Name, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Image, new { @class = "control-label col-md-2" })
<div class="col-md-10">
<input type="file" data-val="true" id="ModifyGenreViewModel_Image" name="ModifyGenreViewModel.Image" />
@Html.ValidationMessageFor(model => model.Image, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="@Resource.Modify" class="btn btn-primary" />
</div>
</div>
</div>
}
私は私のコントローラにブレークポイントを設定すると、私はIDと名前を見ますが、画像は常にnullです。
ありがとうございました!
'@ Html.TextBoxFor(M => m.Image、新しい{タイプ= "ファイル"})'正しいHTML –