After following the previous topic, you should be able to add a DiagramView component to your ASP.NET MVC (Model-View-Controller) user interface.
C#
![]() |
---|
using MindFusion.Diagramming.Mvc; |
In the body of the Index method, create a DiagramView instance and store it in the ViewBag:
C#
![]() |
---|
DiagramView view = new DiagramView("diagramView1"); |
In Index.cshtml add a reference to the MindFusion.Diagramming.Mvc namespace:
Razor
![]() |
---|
@using MindFusion.Diagramming.Mvc |
If you want to use tag helpers for adding MindFusion components to views, import them with the @addTagHelper directive:
Razor
![]() |
---|
@addTagHelper *, MindFusion.Diagramming.Mvc |
Add the component by using either the DiagramView HTML helper:
Razor
![]() |
---|
@Html.DiagramView( |
or alternatively using its Tag helper:
Razor
![]() |
---|
<mindfusion-diagramview |
You can create nodes and links programmatically either by calling Factory methods, or by instantiating objects of respective class and adding them to Items collection:
C#
![]() |
---|
// in controller |
The DiagramView component can preserve its data between postbacks by serializing and deserializing to JSON internally. Call the static FromRequest method
to get this functionality. You can check the request's content type to handle the initial setup of the view and its diagram.
C#
![]() |
---|
// read from request |
Browse the other sections of this help file to learn more about the functionality provided by the MindFusion.Diagramming classes, methods and properties. Follow the tutorials to learn how to populate the diagram model programmatically or create custom item types.