Hello @AnFil!
If you are moving from an MVC, the code behind in controller and view should be significantly similar. In the other hand, if you are coming from WebForms, you'll need to say goodbye to
Page_Load
and other webforms-specific handlers and say hello to the new approaches taken in (if that's your choice) Razor Pages.
While WebForms is gone, TagHelpers is there, but code behind will become significantly different. It will be more like Ext.NET MVC controllers and actions than page events.
While you can find a handful of alternatives on "code behind" alternatives in our current
Ext.NET 5 Examples Explorer (that should not change too much between versions, as the model and actions concept is maintained), you will only find examples for RazorPages in Microsoft documentation by now. At this very moment we are drawing and tinkering ways to make the components from code behind easier and more intuitive.
One way you can do is via
ASP.NET Core's View Components. This is somewhat similar to custom ascx controls from WebForms. It will make the component you drawn available to wherever in the code you use-namespace the added component.
A more pragmatic approach would be just to define the component from code behind and bind it via its
Model
handle.
For instance in your page's
.cs file, say
index.html.cs
, define a public container and add a button within it:
using Ext.Net;
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace MyProject.Pages.forums._6._28.c62883_index
{
public class IndexModel : PageModel
{
public Container Sample { get; set; }
public void OnGet()
{
Sample = new Container()
{
Items =
{
new Button() { Text = "MyButton" }
}
};
}
}
}
Then in the
.cshtml file,
index.cshtml
following the convention above, have this:
@page
@using ExtNetCore7_20200325.Pages.forums._6._28.c62883_index;
@model IndexModel
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Component form code behind - Ext.NET Core Examples</title>
</head>
<body>
<ext-container model="Model.Sample" />
</body>
</html>
There may be, and probably are many other ways to draw components from code behind, including the approaches historically working in Ext.NET MVC give or take. If you find anything that should work, this is the right time for suggestions. We are still improving how code behind interacts with the page as I write this answer.
Hope this helps!