Я получаю следующую ошибку при загрузке файла.
Словарь параметров содержит
пустая запись для параметра 'category_id'
не обнуляемого типа 'System.Int32'
для метода
«System.Web.Mvc.ActionResult
AddProduct (Int32, System.String,
Одиночный, System.String, System.String,
System.String, System.String,
System.String, System.String) 'в
'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();
}
Пожалуйста, предложите несколько полезных ответов.
Спасибо
Ritz