|
Query |
Response |
|
1. Why can't I say @Model.DiagramNetwork.updateNode() ?
|
You need to take diagram instance as shown below not as @Model.DiagramNetwork
Code example:
var diagram = $("#DiagramContent").ejDiagram("instance"); |
|
2. This does not do anything, why:
function diagramNetwork_Click(event) {
var diagram = @Model.DiagramNetwork;
var nodeName = event.element.name;
diagram.updateNode(nodeName, { borderColor: 'Tomato' });
3. This does change the color, but only at the second click:
function diagramNetwork_Click(event) {
event.element.borderColor = 'Tomato';
|
Code example:
//define click event
Diagram.Click = "diagramNetwork_Click";
function diagramNetwork_Click(args) {
if (args.element && args.elementType === "node") {
var diagram = $("#DiagramContent").ejDiagram("instance");
diagram.updateNode(args.element.name, { borderColor: "Tomato" });
}
}
Here is the sample for your reference
Sample: http://www.syncfusion.com/downloads/support/directtrac/general/ze/updateNodesample1650416033
|
|
Query |
Response | ||
|
So the diagram is passed together with the View. In this case, I don't use ViewData.
I think this way is much simpler for C# fans/JS non-fans like me. Basicly the view is just a series of placeholders for the controls. Also you can pass data as objects (see next reply).
I may have 1-2 hours a day to elaborate this if you find this approach useful for others too. |
Yes, we can use the Model to pass the diagram properties from controller to keep the code to minimum instead of ViewData. We have modified your code example and provided below.
Code example:
Controller:
public ActionResult Index()
{
NetworkDiagramPageModel model = new NetworkDiagramPageModel();
BasicShape node = new BasicShape() { Name = "node1", Width = 100, Height = 100, OffsetX = 200, OffsetY = 200 };
model.DiagramNetwork.DiagramModel.Nodes.Add(node);
return View(model);
}
index.cshtml
<div class="diagram_section">
@Html.EJ().Diagram("DiagramContent", Model.DiagramNetwork.DiagramModel)
</div>
Here is code example for click event
function diagramNetwork_Click(args) {
if (args.element && args.elementType === "node") {
var diagram = $("#DiagramContent").ejDiagram("instance");
diagram.updateNode(args.element.name, { borderColor: "Tomato" });
}
}
Note: DiagramContent is an diagram id.
Please refer to the sample below for your reference.
| ||
|
I try to keep the Razor side as simple as I can, so I render the controls like @Model.MyDiagram, or @Model.MyTabs etc. after having defined everything in Model. Another advantage is that I can pass a data object with my model, like Model.Doc, that has e.g. Model.Doc.Title and Model.Doc.Date etc. and than again I just say <div>@Model.Doc.Title</div> and that's all.
Now I see that some controls, in my case so far Splitter and Tab, cannot be referenced this way as I get a nullReference error. So I had to implement Tab by DataView["MyTab"]. This is discouraged by the company style sheet and I can insert the Doc data only one-by-one like DataView["DocTitle"] = Doc.Title which is much uglier than Model.Doc.Title, and
Html.EJ().Tab("mainTab", (Syncfusion.JavaScript.Models.TabProperties)ViewData["MainTab"]).Render();
is much uglier (for me, I know xou like it) than the simplest
@Model.MainTab
Do you know which controls can be referred to as @Model.MyControl and which cannot? Is there any rational reason behind these differences? Can I implement a uniform interface w/os ViewData? |
Similarly, for an tab control use the Model to pass the TabProperties from the controller to keep the code to minimum instead of using the ViewData. Kindly refer to the following code.
[Controller]
[View]
Yes, you can achieve uniform interface either with ViewData or with Model.
|
|
Query |
Response |
|
So it seems it's better to create the controls in View even if some controls let themselves to be created in Model. |
Could you please confirm whether you need tab and other syncfusion controls to be rendered in view similar to our diagram like @Model.DiagramNetwork?, then mention the controls, so that we can forward this query to respective product team.
If we misunderstood your requirement, please let me know how you expect an syncfusion controls to be rendered in view other than normal way as shown below.
@Html.EJ().Diagram("DiagramContent", ViewData["DiagramModel"] as Syncfusion.JavaScript.DataVisualization.Models.DiagramProperties)
|