0

my controller Have 2 Actions :

[HttpPost]
public ActionResult Upload(HttpPostedFileBase[] files)
{
      foreach (HttpPostedFileBase file in files)
      {
           string path = System.IO.Path.Combine(Server.MapPath("~/App_Data"), System.IO.Path.GetFileName(file.FileName));
           file.SaveAs(path);
      }
      ViewBag.Message = "File(s) uploaded successfully";
      return RedirectToAction("Index");
}
//
// GET: /AdultLiteracyTeachers/Details/5
public ActionResult Details(int id = 0)
{
      AdulLiteracyTeachers adulliteracyteachers = db.AdulLiteracyTeachers.Find(id);
      if (adulliteracyteachers == null)
      {
           return HttpNotFound();
      }
      return View(adulliteracyteachers);
}

my view in Create.cshtml

@using (Html.BeginForm(Upload, ControllerName, FormMethod.Post, new { enctype = "multipart/form-data" }))
 <input type="file" name="files" value="Upload Image" />
            <input name="Upload" type="submit" value="Create" />

Problem is only upload is working when I submit button others create etc not working how to call multiple actions in single form create button ?

Guillermo Oramas R.
  • 1,303
  • 2
  • 14
  • 31

1 Answers1

0

I believe you can use the beginform multiple times like this:

@using (Html.BeginForm(Upload, ControllerName, FormMethod.Post, new { enctype = "multipart/form-data" })){
 <input type="submit" name="files" value="Upload Image" />
 }
 @using (Html.BeginForm(Details, ControllerName, FormMethod.Post, new { enctype =  "multipart/form-data" })){
 <input name="Upload" type="submit" value="Create" />
 }

and make sure that the button type="submit".

user2911090
  • 15
  • 1
  • 7