As I have started working on MVC application, I have one query for the same.
I have one textbox (for employee name as I want to retrieve data basis on this) in the page , I want to post the form and get result of 'Employees' data in the same form. (I want to show grid type layout in the same form just below to the textbox)
Could anybody have any idea about how to post form and display data in the same page?
Thanks in advance.
You need a
EmployeeControllerwith two Actions:IndexandAddEmployee.The
Indexaction should retrieve your list of Employees and hand them to the View. You can use ViewData or make the View strongly typed and include the model object in the return:return View(employeeList)The
AddEmployeeaction should contain the logic to add the new employee record, then redirect back to the Index action usingRedirectToAction. This is known as the Post-Redirect-Get pattern. You should never have your users “land” on a POST response, as it can result in double form submissions.In the Employee View: You need a form above and a grid (e.g. MVCContrib Grid) below. The Action of the form should be the
AddEmployeeaction of theEmployeeController.