Asp.net mvc 4 随文件上传一起提交数据
我试图在上传文件的同时发布表单数据(如文本框、复选框等)。我正在使用MVCAsp.net mvc 4 随文件上传一起提交数据,asp.net-mvc-4,Asp.net Mvc 4,我试图在上传文件的同时发布表单数据(如文本框、复选框等)。我正在使用MVC 有人给我一个答案吗 您的Post控制器将如下所示: [HttpPost] public ActionResult YourController(YourModel model1, HttpPostedFileBase file) { if (file != null) { //here file variable will have the file which yo
有人给我一个答案吗 您的Post控制器将如下所示:
[HttpPost]
public ActionResult YourController(YourModel model1, HttpPostedFileBase file)
{
if (file != null)
{
//here file variable will have the file which you have uploaded
}
}
HttpPostedFileBase
包含从视图中发布的文件
在您看来,BeginForm()应该是这样的:
Html.BeginForm(action, controller, FormMethod.Post, new { enctype="multipart/form-data"})
使用MVC有很多方法,上面建议使用强类型,或者这种方法也可以
[HttpPost]
public JsonResult CreateUpdate(FormCollection _formValues, YourModel _extraItem)
{
HttpPostedFileBase files = HttpContext.Request.Files;
//do whatever u wish with ure files here
}
希望它能帮助我解决这个问题。非常感谢大家:D您目前正在尝试什么代码?到底是什么问题?