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.
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.