Render MVC ViewModel without turnkey
No edit summary
(Updated Edited template to July 12, 2025.)
 
(9 intermediate revisions by 3 users not shown)
Line 1: Line 1:
MDriven Turnkey does a lot to get a seamless environment for application development.
<message>Write the content here to display this box</message>
MDriven Turnkey strives to create a seamless environment for application development. If you would like to use parts of the functionality and render a specific ViewModel from MDriven Framework MVC projects, you can do so.


If you would like to make use of parts of the functionality and render a specific viewmodel you can do so.
A good way to get started with this is to look into the MDriven Turnkey View called Turnkey/Views/Turnkey/GenericView.cshtml


This is how turnkey does it internally:
The trick is to make your MVC model of type VMClass -> @model VMClass.
<nowiki>
 
  internal static class MvcRazorPartialViewShared
You can then use this construct to render the ViewModel UI: '''@Html.Partial(Html.RazorPartialFile());'''
  {
* To get the actions for the left side: '''@Html.DisplayLeftSection()'''
    internal static string RenderRazorPartial(ViewModel.Runtime.ViewModel viewModel)
* To get broken constraints: '''@Html.ValidationSummary(true)'''
    {
* To create VMClass instances, use: '''Eco.ViewModel.Runtime.ViewModelHelper'''
      StringBuilder sb = new StringBuilder(2048); // Building big things!
[[Category:MVC]]
                                                  // IMPORTANT! The Using and statements should match the one in the main page!
[[Category:MDriven Turnkey]]
      sb.AppendLine("@using Eco.ViewModel.Runtime");
{{Edited|July|12|2025}}
      sb.AppendLine("@using Eco.MVC");
      sb.AppendLine("@using StreamingAppGenericAPIAndControllers");
      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();
    }
  }
</nowiki>

Latest revision as of 06:01, 20 January 2025

This page was created by Hans.karlsen@mdriven.net on 2019-04-22. Last edited by Edgar on 2025-01-20.

MDriven Turnkey strives to create a seamless environment for application development. If you would like to use 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 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());

  • To get the actions for the left side: @Html.DisplayLeftSection()
  • To get broken constraints: @Html.ValidationSummary(true)
  • To create VMClass instances, use: Eco.ViewModel.Runtime.ViewModelHelper