0
出于某种原因,我的表单发布不起作用,当我在mvc3剃须刀的隐藏领域。它工作正常,如果我删除隐藏的领域,但我需要该领域。表单发布不工作,由于@HiddenFor在mvc3
下面是我的ProductsController post方法和Razor视图
@model CCSPurchasing_MVC.Models.AddNewProductModel
@using CCSPurchasing_MVC.Models
@using (Html.BeginForm("editImage", "Products", FormMethod.Post))
{
@Html.ValidationSummary(true)
@Html.HiddenFor(m => m.ImadeId)
<div class="editor-field">
<p style="margin-left: 300px; margin-right: 20px;">
@Html.LabelFor(m => m.ImageFile)
<input type="file" name="file" id="file" data-val="true" data-val-required="Product Image is required"/>
</p>
</div>
<input type="submit" value="Edit" />
}
[HttpPost]
public ActionResult editImage(AddNewProductModel newP, HttpPostedFileBase file)
{
db = new DBConnection();
if (file != null && file.ContentLength > 0)
{
newP.ImageName = Path.GetFileName(file.FileName);
newP.ImageType = file.ContentType;
newP.ImageSize = file.ContentLength;
newP.ImageFile = new byte[file.ContentLength];
file.InputStream.Read(newP.ImageFile, 0, file.ContentLength);
newP.ImageHeight = 200;
newP.ImageWidth = 200;
}
string result = db.editImage(newP);
return View("editImageUpdate");
}
请分享你的模型 – 2013-04-30 17:36:33
公共类AddNewProductModel { [必需] [显示(名称= “上传图片”) 公共字节[] {镜像文件获得;组; } public int ImadeId {get;组; } } – user2040259 2013-04-30 17:55:27
Plz在您的问题中添加完整的模型(不作为注释)。 – Sharun 2013-05-01 03:36:51