当我开始研究MVC应用程序时,我有一个相同的查询。
我在页面中有一个textbox
(对于我想要检索数据的员工姓名),我想在form and get result of 'Employees' data
中发布same form.
(我想要在grid type layout in the same form
)下面显示textbox
是否有人对how to post form and display data in the same page
有任何想法?
提前致谢。
答案 0 :(得分:1)
您需要EmployeeController
,其中包含两项操作:Index
和AddEmployee
。
Index
操作应检索您的员工列表并将其移交给View。您可以使用ViewData或强烈键入View并在返回中包含模型对象:return View(employeeList)
AddEmployee
操作应包含添加新员工记录的逻辑,然后使用RedirectToAction
重定向回Index操作。这称为Post-Redirect-Get模式。你永远不应该让你的用户在POST响应中“登陆”,因为它可能导致双重表单提交。
在员工视图中:您需要上面的表单和下面的网格(例如MVCContrib Grid)。表单的操作应该是AddEmployee
的{{1}}操作。
答案 1 :(得分:0)