'How to submit @using (Html.BeginForm()) and submit its content to controller
I'm trying to send 6 values from 6 different text boxes to the controller. How can I do this without using 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");
}
Solution 1:[1]
Here's what your controller should look like:
public class AdminController : Controller
{
[HttpPost]
public ActionResult SavePrices(int PriceValueRegularLunch,
int PriceValueRegularLunch1,
int PriceValueRegularLunch2,
int PriceValueRegularLunch3,
int PriceValueRegularLunch4,
int PriceValueRegularLunch5)
{
return RedirectToAction("Lunch", "Home");
}
}
And your view:
@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" />
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | von v. |
