Render MVC ViewModel without turnkey
No edit summary
No edit summary
Line 1: Line 1:
MDriven Turnkey does a lot to get a seamless environment for application development.
MDriven Turnkey does a lot to get a seamless environment for application development.


If you would like to make use of parts of the functionality and render a specific viewmodel you can do so.
If you would like to make use of parts of the functionality and render a specific viewmodel from MDriven Framework MVC projects you can do so.


This is how turnkey does it internally:
A good way to get started with how to do this is to look into the MDriven Turnkey View called Turnkey/Views/Turnkey/GenericView.cshtml
<pre>
 
  internal static class MvcRazorPartialViewShared
The trick is to make your MVC model of type VMClass -> @model VMClass, you can then use this construct to render the ViewModel UI:
  {
 
    internal static string RenderRazorPartial(ViewModel.Runtime.ViewModel viewModel)
@Html.Partial(Html.RazorPartialFile());
    {
 
      StringBuilder sb = new StringBuilder(2048); // Building big things!
In order to get the actions for the left side: @Html.DisplayLeftSection()
                                                  // IMPORTANT! The Using and statements should match the one in the main page!
 
      sb.AppendLine("@using Eco.ViewModel.Runtime");
To get broken constraints: @Html.ValidationSummary(true)
      sb.AppendLine("@using Eco.MVC");
 
      sb.AppendLine("@using StreamingAppGenericAPIAndControllers");
To create VMClass instances you use Eco.ViewModel.Runtime.ViewModelHelper
      sb.AppendLine("@model VMClass");
      RazorControlRenderer razorRenderer = new RazorControlRenderer();
      if (RenderSettings.CheckUseCSSGrid(viewModel))
      {
        CSSGridViewUICreator cssGridViewCreator = new CSSGridViewUICreator(razorRenderer, sb);
        ViewModelRTCreator.CreateDataAndUI(null, cssGridViewCreator, viewModel);
      }
      else
      {
        BootstrapViewUICreator bootstrapViewCreator = new BootstrapViewUICreator(razorRenderer, sb);
        ViewModelRTCreator.CreateDataAndUI(null, bootstrapViewCreator, viewModel); // Create UI delegating work to UICreator
      }
      return sb.ToString();
    }
  }
</pre>

Revision as of 12:49, 22 April 2019

MDriven Turnkey does a lot to get a seamless environment for application development.

If you would like to make use of parts of the functionality and render a specific viewmodel from MDriven Framework MVC projects you can do so.

A good way to get started with how to do this is to look into the MDriven Turnkey View called Turnkey/Views/Turnkey/GenericView.cshtml

The trick is to make your MVC model of type VMClass -> @model VMClass, you can then use this construct to render the ViewModel UI:

@Html.Partial(Html.RazorPartialFile());

In order to get the actions for the left side: @Html.DisplayLeftSection()

To get broken constraints: @Html.ValidationSummary(true)

To create VMClass instances you use Eco.ViewModel.Runtime.ViewModelHelper

This page was edited 79 days ago on 02/10/2024. What links here