请教一个MVC传参到后台的问题
cshtml有这样的代码
<input name="ABC" id="ABC" value="测试数据" />
<input name="btnTest" type="submit" value="测试" onclick="self.location = './btnTest';"/>
后台
public ActionResult btnTest(FormCollection formCollection)
{
var m = formCollection["ABC"]; //为null
var b = Request.Form["ABC"]; //为null
return View();
}
为什么ABC的值,传递不到后台啊,要怎么修改才对啊
------解决方案-------------------- 引用: cshtml改成这样,后台仍然取不到值
<form id="form1" method="post">
<input name="ABC" id="ABC" value="测试数据" />
<input name="btnTest" type="submit" value="测试" onclick="self.location = './btnTest';"/>
</form>
<form id="form1" method="post" action="home/index">
<input name="ABC" id="ABC" value="测试数据" />
<input name="btnTest" type="submit" value="测试" onclick="self.location = './btnTest';"/>
</form>
[HttpPost]
public ActionResult Index(FormCollection formCollection)
{
string abc = formCollection["ABC"];
return View();
}