ファイルをアップロードしようとしていますが、期待どおりに動作しません。 私は次のビューがあります。HttpPostedFileBaseがnullです
@using (Ajax.BeginForm("RegisterBand", "NewProfile", new AjaxOptions() { HttpMethod = "Post",
InsertionMode = InsertionMode.Replace,
}, new { enctype = "multipart/form-data"}))
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-horizontal">
<div class="form-group">
<div class="col-md-10">
Bandname
</div>
<div class="col-md-10">
@Html.EditorFor(x => x.BandProfile.Name, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(x => x.BandProfile.Name, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-10">
Genres
</div>
<div class="col-md-10">
@Html.DropDownListFor(x => x.BandProfile.Genres, Enumerable.Empty<SelectListItem>(), new { @class="", multiple = "multiple", style ="width: 100%;"})
@Html.ValidationMessageFor(x => x.BandProfile.Genres, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-10">
Coverpicture
</div>
<div class="col-md-10">
<input type="file" name="file" id="CoverPicture" />
@Html.ValidationMessageFor(x => x.BandProfile.CoverPicture, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-10">
Description
</div>
<div class="col-md-10">
@Html.EditorFor(x => x.BandProfile.Description, new { htmlAttributes = new { @class = "form-control"} })
@Html.ValidationMessageFor(x => x.BandProfile.Description, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Spara" class="btn btn-success" />
</div>
</div>
</div>
}
はここに私のコントローラである:
[HttpPost]
public ActionResult RegisterBand(ProfileViewModel model, HttpPostedFileBase file)
{
if (ModelState.IsValid == false)
{
return Json(JsonRequestBehavior.AllowGet);
}
var bandProfile = _profileService.CreateBandProfile(model.BandProfile, file, UserId);
if (bandProfile != null)
{
userManager.AddToRole(UserId, "Band");
return RedirectToAction("Index", "Welcome");
}
return View("Index");
}
file
は常にnullでは結果は私が持っている問題です。なぜ私は理解できません。問題を見つけるのを助けることができる人は誰ですか?
私はこの作品、自宅にいるため私のマシン上でこれが問題であるとは思わない:あなたはそれが何の違いを作るかどうかを確認するためにそこに
null
を追加してみてください。私はTFSからコードを入手し、別のコンピュータで試しましたが、これはうまくいきません。 – Bryanコンソールを見ると、POSTはhttp:// localhost:65148/NewProfile/RegisterBand?Length = 10ここには何の長さですか? – Bryan
@ブライアン "別のコンピュータ"と同じブラウザ?私は、あなたがやっていることは、すべてのブラウザでサポートされていないと感じています。 – spender