【发布时间】:2014-12-29 14:34:16
【问题描述】:
我希望将按钮的值接收到 a.aaa
但我得到了 null
a.aaa 需要是 [HttpPost] 中的 "stackOverflow" 字符串
控制器代码
public class DefaultController : Controller
{
// GET: Default
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult Index(Class1 a)
{
return View();
}
}
型号
namespace WebApplication3.Models
{
public class Class1
{
public string aaa { get; set; }
}
}
查看
@model WebApplication3.Models.Class1
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
<button type="button" name="aaa" id="aaa" value="stackOverflow">pressMe</button>
<input type="submit" />
}
【问题讨论】:
-
您在此处发布的代码很好(在我的项目中对其进行了测试,属性
aaa的值在回发时为stackOverflow)。 -
我改一行写成
-
button不是回发控件! -
以及为什么我需要在输入类型中执行 Request["aaa"] 这个示例工作并将值插入到没有 Request["aaa"] 的模型中
-
那么我如何传递按钮值并给它一个名称,如按钮 html 控件,输入控件的值也是名称
标签: c# html asp.net-mvc-5