Ich habe diesen Controller und was ich versuche zu tun ist, um ein Bild an die Steuerung als [Byte] zu senden, das ist mein Controller:MVC HttpPostedFileBase immer null
[HttpPost]
public ActionResult AddEquipment(Product product, HttpPostedFileBase image)
{
if (image != null)
{
product.ImageMimeType = image.ContentType;
product.ImageData = new byte[image.ContentLength];
image.InputStream.Read(product.ImageData, 0, image.ContentLength);
}
_db.Products.Add(product);
_db.SaveChanges();
return View();
}
und auf meiner Ansicht:
@using (Html.BeginForm("AddEquipment", "Equipment", FormMethod.Post)) {
<fieldset>
<legend>Product</legend>
<div class="editor-label">
@Html.LabelFor(model => model.Name)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Name)
@Html.ValidationMessageFor(model => model.Name)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Description)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Description)
@Html.ValidationMessageFor(model => model.Description)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Price)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Price)
@Html.ValidationMessageFor(model => model.Price)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Category)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Category)
@Html.ValidationMessageFor(model => model.Category)
</div>
<div>
<div>IMAGE</div>
<input type="file" name="image" />
</div>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
}
aber das Problem ist, dass der Wert für Bild auf meinem Controller alway null ist, kann ich nicht scheinen keine Informationen über die HttpPostedFileBase zu bekommen
Awesome! vielen Dank für die schnelle Antwort! –
@RiquelmyMelara Keine Probs, ich werde die Antwort auch verbessern. – hutchonoid
Sein „Produkt“ Objekt ist Ich denke, eine Entity Framework „Entity“ geben so eine andere Eigenschaft Hinzufügen könnte seinen Code brechen, wenn er nicht die Config auch –