Hello,
we're evaluating Kendo UI and we are planning to convert an existing application which creates every form it uses from a configuration info in a database.
Doing this in a razor file creates a unreadable code. So the plan is to create the form elements in code behind. I figured out an idea, but I'm not sure if this is the best (or correct) way to do it.
The markup:
@page @model MyModel @{ ViewData["Title"] = "BuildSomethingWonderfulInCodeBehind"; } ... @(Model.Build(Html))
And the code behind:
...
public class MyModel: PageModel
{
public IHtmlContent Build(IHtmlHelper<MyModel> html)
{
StringBuilder result = new();
GetDataSourceWithFormsInfo().ForEach(r =>
{
result.Append(
html.Kendo()
.TextArea()
.Name(r.Name)
.MaxLength(r.Length)
.ToHtmlString());
});
return html.Raw(result.ToString());
}
public void OnGet()
{
}
// in real world the configuration commes from the db
private static List<TextAreaConfig> GetDataSourceWithFormsInfo()
=> new()
{
new TextAreaConfig("name", 20),
new TextAreaConfig("surname", 30),
new TextAreaConfig("street", 40),
new TextAreaConfig("town", 50),
};
privateclassTextAreaConfig
{
public readonly int Length;
public readonly string Name;
public TextAreaConfig(string name, int length)
{
Name = name;
Length = length;
}
}
}
....
This is a working test fragment just to show the principle. It creates 4 textareas. So it looks that this is a possible path to port the existing app to Kendo UI.
But is the correct way to solve this requirement?