gpt4 book ai didi

asp.net-mvc - 如何提交@using (Html.BeginForm()) 并将其内容提交给 Controller

转载 作者:行者123 更新时间:2023-12-05 03:15:27 24 4
gpt4 key购买 nike

我正在尝试将 6 个值从 6 个不同的文本框发送到 Controller 。如何在不使用 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");
}

最佳答案

Controller 应该是这样的:

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

关于asp.net-mvc - 如何提交@using (Html.BeginForm()) 并将其内容提交给 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15892022/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com