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
  • Buy Minocycline Online - Special offer: Save up to $498 - buy antibiotics online and get discount for all purchased!
    Michaelbut | 12/12/2023 7:38:21 PM
  • Thanks for wonderful information. What trips can you recommend in 2024? Astro tourism, eco diving, home swapping, train stations are the new food destinations,sports tourism, coolcationing, gig tripping, private group travel?
    BryanLor | 1/23/2024 8:54:39 PM
  • Bitcoin Fobit is an A.I bitcoin generator that works by solving mathematical equations in the process of mining bitcoins. The procedure is very powerful and robust, which has generated a search for funds amid a public address. .The process of generating bitcoins is automated, with the machine learning technology. Basically, the Bitcoin generator will look for Bitcoins in different paper wallets by running a variety of equations and calculations. The process is fully automated and has been programmed to mine Bitcoin through 11 algorithms. This feature has made it one of the most successful mining software on the market today. There is no set amount of bitcoins that a user can earn, but there are always available funds to be found. You may be surprised at how much you can earn. This system is legitimate and always works without errors or bugs. https://easybitcoin.eu.org/ref=3Cbq7aT1tY8kMxWLbitaG7yT6bPbKChq64/
    Erica | 2/3/2024 2:26:40 PM
  • I’m not sure where you’re getting your information, but great topic. I needs to spend some time learning much more or understanding more. Thanks for magnificent information I was looking for this information for my mission.
    RobertNax | 2/14/2024 6:16:25 AM
  • Special offer for baclofen: buying baclofen online uk only 0.66 per pill - https://nieuws.top010.nl/wp-content/uploads/cms/buy-baclofen-online/, get free AirMail shipping or free courier delivery and discount for all purchased! Two free pills (Viagra or Cialis or Levitra) available with every order.
    baclofen-KaT | 2/16/2024 2:53:18 PM