2013-04-09 29 views
0

我試圖從6個不同的文本框中發送6個值到控制器。我如何在不使用JavaScript的情況下做到這一點?如何提交@using(Html.BeginForm())並將其內容提交給控制器

@using (Html.BeginForm("Save", "Admin")) 
    { 
@Html.TextBox(ValueRegular.ToString(FORMAT), new { @name = "PriceValueRegularLunch" }) 
@Html.TextBox(ValueRegular1.ToString(FORMAT), new { @name = "PriceValueRegularLunch1" }) 
@Html.TextBox(ValueRegular2.ToString(FORMAT), new { @name = "PriceValueRegularLunch2" }) 

     <input type="submit" name="SaveButton" value="Save" /> 
} 


[HttpPost] 
     public ActionResult SavePrices(int PriceValueRegularLunch) 
     { 
      return RedirectToAction("Lunch", "Home"); 
     } 
+1

嘗試利用模式也.. – ssilas777 2013-04-09 03:15:57

回答

2

這是你的控制器看起來應該像什麼:

public class AdminController : Controller 
{   
    [HttpPost] 
    public ActionResult SavePrices(int PriceValueRegularLunch, 
     int PriceValueRegularLunch1, 
     int PriceValueRegularLunch2, 
     int PriceValueRegularLunch3, 
     int PriceValueRegularLunch4, 
     int PriceValueRegularLunch5) 
    { 
     return RedirectToAction("Lunch", "Home"); 
    } 
} 

而且你的觀點:

@using (Html.BeginForm("SavePrices", "Admin")) 
{ 
    @Html.TextBox("PriceValueRegularLunch") 
    @Html.TextBox("PriceValueRegularLunch1") 
    @Html.TextBox("PriceValueRegularLunch2") 
    @Html.TextBox("PriceValueRegularLunch3") 
    @Html.TextBox("PriceValueRegularLunch4") 
    @Html.TextBox("PriceValueRegularLunch5") 

    <input type="submit" name="SaveButton" value="Save" /> 
} 
相關問題