I am getting the following error whilst uploading a file.
The parameters dictionary contains a null entry for parameter 'category_id' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult AddProduct(Int32, System.String, Single, System.String, System.String, System.String, System.String, System.String, System.String)' in 'Ecommerce.Controllers.AdminController'. To make a parameter optional its type should be either a reference type or a Nullable type. Parameter name: parameters
I am using a dialog box.
The View
<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>
The Controller Action
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();
}
Please suggest some useful answers.
Thanks
Ritz