asp.net-mvc 如何提交@using (Html.BeginForm()) 并将其内容提交给控制器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15892022/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 02:43:45 来源:igfitidea点击:
How to submit @using (Html.BeginForm()) and submit its content to controller
提问by NNassar
I'm trying to send 6 values from 6 different text boxes to the controller. How can I do this without using JavaScript?
我正在尝试将 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");
}
回答by von v.
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" />
}

