Dynamic MVC Order Entry Tutorial - Customize Orders Details

This tutorial has been updated to version 3.0.
Sat, 6 Sep. 2016 - Chris Perry

Customize Beyond Scaffolding

So far we have customized forms using scaffolding and attributes. For many customizations this will not be enough. One of the import things about Dynamic MVC is that although it will get you out the gate quickly, it will get out of your way when you need to go out on your own. We can customize a specific view for a particular entity by copying the view from the shared folder and pasting it into the specific folder for the entities controller. We can do this for the Order entity because we already created a custom Order Controller. This is following normal mvc convention and we are no longer using dynamic route for order. We could blow away all the dynamic code in our controller that we copied and start fresh for order without worring about dynamic mvc getting in our way. For this tutorial we won't do that but it is a very important thing to understand.

Show Order Detail Information

We are going to display the order information as master detail form. We are going to show the order information using three columns. We can leverage the information stored in the Dynamic View Model by querying the DynamicEditorViewModels.

Show OrderLines

The next thing we need to do for the order details form is to show the order lines. To do this we will create an HTML table. The create, edit and delete hyperlinks will open up the appropriate dynamic forms for the OrderLine. Notice the ReturnUrl has been set to have that form return to the details form after post.

Customize The Create OrderLine Page

If we run the application, navigate to an order and click the "Add New Product" hyperlink, we can see the Create OrderLine page shows the OrderId and total. This isn't really needed. To hide the OrderId we can decorate the OrderId property with UIHint("DynamicEditorHidden"). To hide the Total property we are going to set the CreatePropeties property of the DynamicEntity attribute to "OrderId,ProductId,Quantity". Notice that we did include OrderId in the page but chose to make it hidden. This is important because it is needed to attach the OrderLine to the Order on the form post.

Modify The Database Query For The Order Detail Page

If we run the application now and click "Add New Product", the new OrderLine will be saved to the database but will not show up on the details form. This is because we are not retrieving it from the database by default. By default, Dynamic MVC will retrieve complex properties attached to the entity along with the entity itself. We can modify this using the InstanceIncludes property of the DynamicEntity attribute that decorates the Order model. Set this property to "OrderLines.Product,Customer,OrderStatus".

Add Business Logic

Business Logic has gotten a last minute upgrade in version 3. Any Method can now be decorated with the dynamicmethod attribute. You can specify an invoker class for further customization.

You can create your own Invoker and pass the name of it into your Dynamic method. Invokers give you total control of how you would like to invoke the method and redirect. You can even include messages that show up on other pages using temp data.

See the completed download for details. This business logic additions were a last minute change and is not included in previous tutorial downloads.

COMMENTS Add Comment
  • Copying to a folder named as the model you want a customized view for doesn't seem to work. I have a model Guest and copied DynamicCreate.cshtml into a folder named Guest under the Views folder and it still uses the shared one. I tried to go through the code and couldn't really figure out how this worked, but using Glimpse I noticed that it looked in a folder Dynamic. When I renamed the folder from Guest to Dynamic, it DID use the customized view (in the Dynamic folder)...
    RobertE | 12/8/2015 11:03:38 PM
  • Robert, Thanks for the comment. I can see the issue here. The view that is getting used is determined by default MVC convention and has not been modified by Dynamic MVC. The routes are set by DynamicMVC to direct traffic to the DynamicController if a concrete controller has not be specified in the project. If you want MVC to use a view in your "Guest" folder you must first create a GuestController class in your controllers folder. If you want the views to be dynamic you can simply copy, paste, and rename the DynamicController class. Once you have created a concrete controller DynamicMVC will let default mvc controller naming convention work its magic and no longer use a dynamic route for that particular entity. Does this help?
    Chris Perry | 12/9/2015 4:12:11 AM
  • Smart thinikng - a clever way of looking at it.
    ylT1ITnZ | 3/30/2016 7:02:15 AM
  • Thanks for helping me to see things in a difrnfeet light. http://zhgpzmay.com [url=http://gpwcnytuk.com]gpwcnytuk[/url] [link=http://xflkpaec.com]xflkpaec[/link]
    ZqEbsMnE | 4/8/2016 9:04:31 AM
  • Tem como deixar o link para fazer o download do Banco de Dados. Obg
    alysson | 9/3/2016 5:01:14 AM
  • I congratulate, what necessary words..., an excellent idea https://how6youtoknowc.org/map.php
    Asepanum | 3/9/2022 2:31:00 AM