views:

26

answers:

2

Hi All,

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.

A: 

I know this is not the answer you're asking for, but it seems to me you are trying to mimic the post-back behavior of WebForms.

Don't do that.

You should NOT render views from post actions. If the user tries to refresh the result page, the post action will be executed again. This can result in duplicated data (in a database web front-end application, for instance).

You should use the PRG pattern. Please read this, this or this.

rsenna
+1  A: 

You need a EmployeeController with two Actions: Index and AddEmployee.

The Index action 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 AddEmployee action should contain the logic to add the new employee record, then redirect back to the Index action using RedirectToAction. 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 AddEmployee action of the EmployeeController.

Dave Swersky