Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To generate an edit form using ASP.Net MVC 2 scaffolding, follow these steps:

  1. Create a new ASP.Net MVC 2 project in Visual Studio.

  2. Add a new model class to the project that represents the data you want to edit.

  3. Create a new controller class that will handle the editing of the data.

  4. In the controller class, add an action method that will return the view for the edit form.

  5. Decorate the action method with the HttpGet attribute to specify that it should only respond to GET requests.

  6. Add a parameter to the action method that will accept the ID of the data being edited.

  7. Inside the action method, use LINQ to retrieve the data from the database and pass it to the view.

  8. Create a new Razor view that will render the edit form.

  9. Use the scaffolding feature of Razor to generate the HTML for the form.

  10. Decorate the form elements with the appropriate attributes to bind them to the model properties.

  11. Add a submit button that will post the data back to the server.

  12. In the controller class, add an action method that will handle the update of the data.

  13. Decorate the action method with the HttpPost attribute to specify that it should only respond to POST requests.

  14. Add a parameter to the action method that will accept the updated data.

  15. Inside the action method, use LINQ to update the data in the database.

  16. Redirect the user back to the index view that displays the list of data items.

  17. Test the edit form to ensure that it works correctly.