我有两个Create
方法,一个用HttpGet
装饰,另一个用HttpPost
装饰。将数据从html表格保存到列表
@{
ViewBag.Title = "Create";
}
<h2>Create</h2>
<form action="/" method="post">
<input type="text" name="txt" value="" />
<input type="submit" />
</form>
的方法:我有一个为第一个看起来像这样创建视图
List<string> myList = new List<string> { "element1", "element2", "element3" };
public ActionResult Create()
{
return View();
}
[HttpPost]
public ActionResult Create(string txt)
{
//myList.Add(Request.Form["txt"]);
myList.Add(txt);
return View();
}
我simly试图从我的形式传递数据上的按钮,我的第二个Create()
并保存到myList
。
我需要一些关于如何使这项工作的建议。
..什么是不工作?这似乎工作得很好(假设你的'
@RudiVisser它只是没有添加到列表 –
@RobertRoss什么你的意思是“不添加”?在第二个请求'myList'只包含默认值? – feeeper