2014-04-16 47 views
0

我的控制器有2個動作:多個動作4

[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); 
} 

我在Create.cshtml視圖

問題是 只能上傳工作,當我提交按鈕其他創建等不工作 如何調用單個窗體中的多個操作創建按鈕?

+0

您要發佈到詳細信息操作的標識 – Ni3

+0

我的詳細信息正在運行,但上傳不起作用。當我把行動和控制器名稱詳細sto.pped工作 –

+0

你是否意味着這個'RedirectToAction(「索引」)''RedirectToAction(「詳細信息」)'? – AaronLS

回答

0

我相信你可以多次使用beginform這樣的:

@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" /> 
} 

,並確保按鈕類型=「提交」。