Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET MVC Master Detail Entry Form

Tags:

I’m trying to implement an order entry form using ASP.NET MVC but facing a lot of difficulties. All the samples that I found are related to viewing master detail forms, and none for adding or editing.

Suppose I have two tables: Order and OrderLines that are related to each others with one-to-many relationship. In the main view I had a “New” button when clicked it should show a new order view composed of the order fields, a grid that shows the order lines, and a “Save” button that when clicked will persist the whole order along with its lines into a database. The grid should have three buttons: “Add Line”, “Edit Line”, and “Delete Line”. When the “Add Line” is clicked a new view should be shown that allows the user to add the line to the order view grid lines –at this stage the database is not affected-. When the user clicks “Edit Line” a view will be shown that allows the user to edit the selected line and when done update the order grid lines.

The most difficult problems are:

How to pass the order and its lines collection between the order view and the order line views?

How to update the order view based on changes in the order line view?

And how to persist changes between views without the database being involved?

Is there a concrete example that shows how to implement this using MVC?

Views

Your help and feedback is appreciated.

like image 359
Emad Avatar asked Jan 10 '11 11:01

Emad


People also ask

What is the entry point for ASP.NET MVC?

The module and handler are the entry points to the ASP.NET MVC framework. They perform the following actions: Select the appropriate controller in an MVC Web application.

Can we use master page in MVC?

In addition to supporting partial views, ASP.NET MVC also supports the ability to create "master page" templates that can be used to define the common layout and top-level html of a site.

How can create details in MVC?

Select the scaffolding template. Template dropdown will show default templates available for Create, Delete, Details, Edit, List, or Empty view. Select "List" template because we want to show the list of students in the view. Now, select Student from the model class dropdown.


2 Answers

Pleas have a look at my blog post on creating master detail form in asp.net mvc. it also contains demo project that you can download

like image 118
Muhammad Adeel Zahid Avatar answered Sep 25 '22 18:09

Muhammad Adeel Zahid


Unlike WebForms, ASP.NET MVC does not try to hide the stateless nature of HTTP. To work with a complex object across multiple forms you have a couple of options:

  • Save the object on the server with each change so that the updated object is available using only an id
  • Use jquery to populate the order line form and save details to the main form

I usually go with the client side option myself, with the main form having hidden fields for the data that will be edited in the subform. You may find the server side option easier though - if you really don't want to involve the database you can keep your partially updated object in the session.

like image 25
Tom Clarkson Avatar answered Sep 22 '22 18:09

Tom Clarkson