0
我剛剛嘗試了很多我發現的東西,但最終沒有任何成功。HttpPostedFileBase varbinary(max)
首先我有下一個代碼,只是做的事情確定,但不保存圖像。
如何將圖像保存到varbinarymax中?以及如何將它們展示給下一個視圖?
觀點:
<div class="form-group">
@Html.LabelFor(model => model.Logo, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@*@Html.EditorFor(model => model.Logo, new { htmlAttributes = new { @class = "form-control" } })*@
@Html.TextBoxFor(model => model.Logo, new { type = "file" })
@Html.ValidationMessageFor(model => model.Logo, "", new { @class = "text-danger" })
</div>
</div>
控制器:
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Create([Bind(Include = "Id,Name,Address,Description,Mail,Phone,Small_Description")] School school)
{
if (ModelState.IsValid)
{
db.School.Add(school);
await db.SaveChangesAsync();
return RedirectToAction("Index");
}
return View(school);
}
型號:
public partial class School
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
public School()
{
this.Product = new HashSet<Product>();
}
public int Id { get; set; }
public string Name { get; set; }
public string Address { get; set; }
public string Description { get; set; }
public string Mail { get; set; }
public int? Phone { get; set; }
public byte[] Logo { get; set; }
public string Small_Description { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<Product> Product { get; set; }
}