Bir dosya yüklemeye çalışıyorum ama beklendiği gibi çalışmıyor. Aşağıdaki görünüme sahip: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>
}
İşte benim denetleyicisi geçerli:
[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
hep boş olarak sonuçlandığını ben sorun var. Nedenini anlamıyorum. Sorunu bulmak için bana yardımcı olabilecek herkes var mı?
ben bu çünkü evde makinede sorun var sanmıyorum, bu çalışır. Kodu TFS'den aldım ve sonra başka bir bilgisayarda denedim ve bu işe yaramıyor. – Bryan
Konsola baktığımda, POST'un http: // localhost: 65148/NewProfile/RegisterBand için yapıldığını görebiliyorum? Uzunluk = 10 Burada Uzunluk Nedir? – Bryan
@Bryan "Başka bir bilgisayarda" aynı tarayıcı? Yaptığınız şeyin tüm tarayıcılarda desteklenmediğini hissediyorum. – spender