2

6 つの異なるテキスト ボックスから 6 つの値をコントローラーに送信しようとしています。JavaScript を使用せずにこれを行うにはどうすればよいですか?

@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");
        }
4

1 に答える 1

4

コントローラーは次のようになります。

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" />
}
于 2013-04-09T02:00:51.387 に答える