我目前正在使用Sanderson所著的Pro ASP.NET MVC 2框架。但我正在使用MVC 3框架。这个问题与我以前的问题有关。我收到以下错误..。
值不能为空或空。参数名称: contentType指向线.
返回文件(product.Picture1,product.ImageMimeType);
他在书里说..。
我们不希望这些属性在产品编辑UI中直接可见。我们可以使用ScaffoldColumn(false)从自动生成的UI中排除ImageMimeType。我们不需要给出任何关于ImageData的提示,因为ASP.NET MVC的内置对象编辑器模板无论如何都不会构建byte[]属性--它只支持字符串、int和DateTime5等“简单”类型的属性。
所以我已经这么做了,但仍然得到同样的错误信息?如果可能的话,如何解决这个问题。
Index.cshtml
@foreach (var item in Model)
<td>
<img src="@Url.Action("GetImage", "ProductCategoryL2", new { id =
@item.SubProductCategoryID })" alt="" height="100" width="100" />
</td>
Edit.cshtml
@using (Html.BeginForm("ProductCategoryL2", "GetImage", FormMethod.Post,
new { @enctype = "multipart/form-data" }))
{
<div class="editor-field">
<img src="@Url.Action("GetImage", "ProductCategoryL2", new { id =
@Model.SubProductCategoryID })" alt="" />
@Html.ValidationMessage("Picture1", "*")
<input type="file" name="Image" size="23"/>
</div>
}
cs文件
public FileContentResult GetImage(int id)
{
var product = db.SubProductCategory2.First(x =>
x.SubProductCategoryID == id);
return File(product.Picture1, product.ImageMimeType); //Value cannot be null or empty. Parameter name: contentType
}
另一个cs文件
[ScaffoldColumn(false)]
public string ImageMimeType { get; set; }
我已经在SQLServer2008R2中设置了ImageMimeType字段,与书中的内容完全相同。我正在使用VS 2010 ASP.NET 4.0 MVC3。提前谢谢。表名为SubProductCategory2。
发布于 2011-03-19 12:22:55
在方法中放入一个断点,并检查product.ImageMimeType的值。我想你会发现它要么是空字符串要么是空字符串。不是从数据库中检索它,就是数据库中没有包含任何内容。
https://stackoverflow.com/questions/5364615
复制相似问题