Tengo siguiendo Ajax.BeginForm en la página de visualización
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"> } entonces tengo el siguiente método de controlador en la clase de controlador FileUpload
[HttpPost] public ActionResult Financing_Product_Feature_Upload(HttpPostedFileBase file, string productid) { pero una vez que hago clic en el botón Enviar anterior, no se dirige al método del controlador Financing_Product_Feature_Upload
La serialización de MVC funciona en los atributos de nombre. El nombre del control de formulario debe coincidir con los parámetros de acción del controlador MVC. En su caso, supongo, debería recibir un error en la consola del navegador cuando presiona el botón "Enviar" que dice "no se encontró una acción coincidente en el controlador FileUpload" o algo que le dé ese significado.
@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 } }intente agregar @ en 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"> }Agregue @ antes de usar:
@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"> } Y cambie el nombre del HttpPostedFileBase file a files porque este es el nombre de entrada de su archivo.