Asp.net mvc 3 Pass image&;从视图到控制器的数据
我想在点击提交按钮时将图像和一些数据从视图传递到控制器。 下面是我的密码 我的看法Asp.net mvc 3 Pass image&;从视图到控制器的数据,asp.net-mvc-3,razor,Asp.net Mvc 3,Razor,我想在点击提交按钮时将图像和一些数据从视图传递到控制器。 下面是我的密码 我的看法 @using (Html.BeginForm("AccountPhotoPost", "Post", FormMethod.Post, new {enctype = "multipart/form-data", accountId = Model.accountId })) { <text>Post Photo : </text> <input type="file"
@using (Html.BeginForm("AccountPhotoPost", "Post", FormMethod.Post, new {enctype = "multipart/form-data", accountId = Model.accountId }))
{
<text>Post Photo : </text> <input type="file" name="file" id="file" />
<input type="submit" value="Post Photo" id="saveButton"/>
}
这里的问题是,因为它是FormMethod.Post,所以数据并没有从视图传递到控制器&若我删除了它,那个么数据就被传递了,但映像并没有被传递
我怎样才能将两者同时发送?试试这个
@model SomeModel
@using (Html.BeginForm("AccountPhotoPost", "Post", FormMethod.Post, new {enctype = "multipart/form-data"}))
{
<text>Post Photo : </text> <input type="file" name="file" id="file" />
@Html.HiddenFor(model => model.accountId )
<input type="submit" value="Post Photo" id="saveButton"/>
}
试试这个,
HttpPostedFileBase hpf=Request.Files[“file”]作为HttpPostedFileBase;
var httpPostedFileBase=Request.Files[“file”];
如果(httpPostedFileBase!=null&&(hpf!=null&&httpPostedFileBase.ContentLength>0))
{
var postedFileBase=Request.Files[“file”];
if(postedFileBase!=null)
{
fileName=postedFileBase.fileName;
BinaryReader=新的BinaryReader(postedFileBase.InputStream);
byte[]attachmentBinary=reader.ReadBytes((int)postedFileBase.ContentLength);
hcUserReview.AttachmentByteValue=attachmentBinary;
hcUserReview.FileName=文件名;
}
}
@model SomeModel
@using (Html.BeginForm("AccountPhotoPost", "Post", FormMethod.Post, new {enctype = "multipart/form-data"}))
{
<text>Post Photo : </text> <input type="file" name="file" id="file" />
@Html.HiddenFor(model => model.accountId )
<input type="submit" value="Post Photo" id="saveButton"/>
}
[HttpPost]
public ActionResult AccountPhotoPost(SomeModel model ,HttpPostedFileBase file)
{
var Id = model.accountId;
}