gpt4 book ai didi

asp.net-mvc - 在 Controller 中获取 HTML 控件值

转载 作者:行者123 更新时间:2023-12-04 10:19:07 25 4
gpt4 key购买 nike

我想在 Controller 中获取 HTML 文本框值。下面是我的查看代码

@using (Html.BeginForm("SaveValues", "TestGrid",FormMethod.Post))
{
<table>
<tr>
<td>Customer Name</td>
<td>
<input id="txtClientName" type="text" />
</td>
<td>Address</td>
<td>
<input id="txtAddress" type="text" /></td>
<td>
<input id="btnSubmit" type="submit" value="Submit" /></td>
</tr>
</table>}

请检查下面我的 Controller 代码以获取值
[HttpPost]
public ActionResult SaveValues(FormCollection collection)
{
string name = collection.Get("txtClientName");
string address = collection.Get("txtAddress");
return View();
}

我得到空值

最佳答案

将 name 属性添加到您的输入字段,例如:

<input id="txtClientName" name="txtClientName" type="text" />

关于asp.net-mvc - 在 Controller 中获取 HTML 控件值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15738754/

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