[英]Ajax.BeginForm send parameters to controller
我在Ajax.BeginForm
上关注Ajax.BeginForm
using (Ajax.BeginForm("Financing_Product_Feature_Upload", "FileUpload", new { productid = @ViewBag.Product_ID }, new AjaxOptions() { HttpMethod = "POST" }, new { enctype = "multipart/form-data"}))
{
@Html.AntiForgeryToken()
<input type="file" name="files"> <input type="submit" value="Upload File to Server">
}
然后我在FileUpload
控制器类中有以下控制器方法
[HttpPost]
public ActionResult Financing_Product_Feature_Upload(HttpPostedFileBase file, string productid)
{
但是一旦我点击上面的提交按钮, Financing_Product_Feature_Upload
不会指向Financing_Product_Feature_Upload
控制器方法
尝试在 enctype 中添加 @
using (Ajax.BeginForm("Financing_Product_Feature_Upload", "FileUpload", new { productid = @ViewBag.Product_ID }, new AjaxOptions() { HttpMethod = "POST" }, new { @enctype = "multipart/form-data"}))
{
@Html.AntiForgeryToken()
<input type="file" name="file"> <input type="submit" value="Upload File to Server">
}
MVC 序列化适用于名称属性。 表单控件的名称需要与 MVC 控制器操作参数匹配。 在您的情况下,我想,当您点击“提交”按钮时,您应该在浏览器控制台中收到错误消息,说“在控制器 FileUpload 上没有找到匹配的操作”或具有该含义的其他内容。
@using (Ajax.BeginForm("Financing_Product_Feature_Upload", "FileUpload", new { productid = @ViewBag.Product_ID }, new AjaxOptions() { HttpMethod = "POST" }, new { enctype = "multipart/form-data" }))
{
@Html.AntiForgeryToken()
<input type="file" name="files"> <input type="submit" value="Upload File to Server">
}
public class FileUploadController : Controller
{
[HttpPost]
public ActionResult Financing_Product_Feature_Upload(HttpPostedFileBase files, string productid)
{
// Action code goes here
}
}
使用前加@
:
@using (Ajax.BeginForm("Financing_Product_Feature_Upload", "FileUpload", new { productid = ViewBag.Product_ID }, new AjaxOptions() { HttpMethod = "POST" }, new { enctype = "multipart/form-data"}))
{
@Html.AntiForgeryToken()
<input type="file" name="files"> <input type="submit" value="Upload File to Server">
}
并将HttpPostedFileBase file
重命名为files
因为这是您的文件输入名称。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.