1

In my project I have View Like this :

@using (Html.BeginForm(MVC.Admin.Sys.ActionNames.Index, MVC.Admin.Sys.Name, FormMethod.Post, new { enctype = "multipart/form-data" }))
{...}

And My actions Are :

 [HttpGet]
    public virtual ActionResult Index()
    {...}
[HttpPost]
public virtual ActionResult Index(EditSysInfo sysInfoViewModel,HttpPostedFileBase file)
    {}

in View I have :

 <input type="file" name="file"/> ... submit button

but when Click On the submit button dont cann Post action , and redirect to httpget Action . yesterday its work fine . I dont know why doesnt run ? Today I just Install Microsoft.AspNet.Web.Optimization . when Change to this :

@using (Html.BeginForm())

Its work fine , but cant post file to action this way .

I try to getting file in Action Like This :

HttpPostedFileBase logo = Request.Files.Get("file");

Allways Count Request.Files is Zero.

thanks . Updated:

[AcceptVerbs(HttpVerbs.Post)]
    public  ActionResult Index(EditSysInfo sysInfoViewModel,HttpPostedFileBase file)
    {...}

and In View :

@using (Html.BeginForm(MVC.Admin.SysInfo.ActionNames.Index, MVC.Admin.SysInfo.Name, FormMethod.Post, new { enctype = "multipart/form-data" }))
{
         <input type="file" name="file"/>
}
tereško
  • 58,060
  • 25
  • 98
  • 150
Psar Tak
  • 682
  • 1
  • 9
  • 27

1 Answers1

0

I think your problem is, BeginForm helper method is not able to properly generate the form tag with the action attribute value. It could be because the parameters you provided are not valid.

Try passing the action name and controller name as strings.

The below code should work fine.

@using (Html.BeginForm("Index", "Home", FormMethod.Post,
                                                new { enctype = "multipart/form-data" }))
{
   <input type="file" name="file"/>
   <input type="submit"/>
}

Assuming your Index action method in HomeController. Update the second parameter if your controller name is different.

Shyju
  • 214,206
  • 104
  • 411
  • 497