我收到以下错误,而上传文件。如何上传图片
参数字典包含参数 'CATEGORY_ID' 非空类型 'System.Int32' 的方法 “ System.Web.Mvc.ActionResult addProduct命令的 一个 空条目(的Int32,System.String , 单个,System.String,System.String, System.String,System.String, System.String,System.String)'in 'Ecommerce.Controllers.AdminController'。 为了使说明可选择其类型 应该是引用类型或 空类型。参数名称: 参数
我正在使用一个对话框。
观
<script type="text/javascript">
$(function() {
$("#dialog").dialog({
bgiframe: true,
height: 140,
modal: true,
autoOpen: false,
resizable: false
})
});
</script>
<div id="dialog" title="Upload files">
<% using (Html.BeginForm("Upload", "File", FormMethod.Post, new { enctype = "multipart/form-data" }))
{%>
<p><input type="file" id="fileUpload" name="fileUpload" size="23"/> </p>
<p><input type="submit" value="Upload file" /></p>
<% } %>
</div>
<p>
<label for="image_name">image_name:</label>
<a href="#" onclick="jQuery('#dialog').dialog('open'); return false">Upload File</a>
<%= Html.ValidationMessage("image_name", "*") %>
</p>
控制器动作
public ActionResult AddProduct(int category_id, string product_name, float product_price, string product_desc, string weight, string image_name, string img_content, string available_qty, string isFeature)
{
foreach (string inputTagName in Request.Files)
{
HttpPostedFileBase file = Request.Files[inputTagName];
if (file.ContentLength > 0)
{
string filePath = Path.Combine(HttpContext.Server.MapPath("../Uploads"), Path.GetFileName(file.FileName));
string filecontent = Path.Combine(HttpContext.Server.MapPath("../Uploads"), Path.GetFileName(file.ContentType));
image_name = Path.GetFileName(file.FileName);
img_content = Path.GetFileName(file.ContentType);
file.SaveAs(filePath);
}
}
AdminImplementation _adminImplementation = new AdminImplementation();
Boolean isfeature = Convert .ToBoolean(isFeature);
if (isfeature)
{
isFeature = "Featured";
}
else
{
isFeature = "NotFeatured";
}
int i = _adminImplementation.addproduct(category_id, product_name, product_price, product_desc, weight,image_name ,img_content ,available_qty ,isFeature);
ViewData["succm"] = "Product added successfully";
return View();
}
请提出了一些有用的答案。
感谢
丽思
我们将需要的方法签名也。 – Kezzer 2009-11-09 13:47:58
现在,我已经固定你的答案时,请提供该最初呈现在页面的ViewResult。我需要知道缺失值在哪里。此外,如果你不知道为什么这个错误是发生我建议您访问www.asp.net/mvc/,因为它似乎你不理解MVC架构的ASP.NET中的一些基本要素。 – Kezzer 2009-11-09 16:07:28