我正在使用MVC4和Entity Framework 5编写一个非常小的应用程序。
我想添加一个产品,并为该产品存储图像。
我有一个模型。
[Table("CatalogItem")]
public class CatalogItemModel
{
[Key]
public int CatalogItemId { get; set; }
public string Description { get; set; }
public double Price { get; set; }
public int ProductCount { get; set; }
public string Size { get; set; }
public string Sku { get; set; }
[Column(TypeName = "image")]
public byte[] Image { get; set; }
[Display(Name = "Display Catalog Item")]
public bool DisplayItem { get; set; }
}
我的控制器。它从未被调用过。
[HttpPost]
public ActionResult Create(CatalogItemModel catalogitemmodel)
{
if (ModelState.IsValid)
{
db.CatalogItemModels.Add(catalogitemmodel);
db.SaveChanges();
return RedirectToAction("Index");
}
return View(catalogitemmodel);
}
我的观点表单
<fieldset>
<legend>CatalogItemModel</legend>
<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.ProductCount)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.ProductCount)
@Html.ValidationMessageFor(model => model.ProductCount)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Size)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Size)
@Html.ValidationMessageFor(model => model.Size)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Sku)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Sku)
@Html.ValidationMessageFor(model => model.Sku)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.DisplayItem)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.DisplayItem)
@Html.ValidationMessageFor(model => model.DisplayItem)
</div>
<div class="editor-label">
@Html.LabelFor(m=>m.Image)
</div>
<input name="Image" type="file"/>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
当我尝试在文件输入中添加图片并发布新目录时,会出现错误。
该输入不是有效的Base-64字符串,因为它包含一个非Base-64字符、超过两个填充字符或填充字符中存在非法字符。
catalogitemmodel
怎么样了?它是如何创建的?如果断点没有被触发,那么问题就出现在之前了。 - nick_wCatalogItemModel.Image
时,代码是什么? - nick_w