Differences among Blazor InputText, HTML Input and direct assigning from C# code

Viewed 999

I am learning this new Blazor framework and was wondering what is the difference between using EditForm and it's components vs regular html inputs vs direct assigning from code for posting into database.

For example Input and InputText:

<EditForm Model="Advert" OnValidSubmit="Create">
<Input @bind-Value="advert.City" />
<InputText @bind-Value="advert.City"/>
</EditForm>

And directly from code by assigning a value advert.City="London. Does it cause any disadvantages or security issues?

public async Task Create()
    {
        try
        {
            advert.City = "London";
            await advertRepository.CreateAd(advert);
            //navigationManager.NavigateTo("ProductsList");
        }
        catch (Exception ex)
        {
            //...
            Console.WriteLine(ex.Message);
        }
    }
1 Answers

input Html elements and Forms input components are used to gather data from the user. In that respect their functionality is more or less identical. You use an Html input text or InputText component to get data from the user. Actually, the underlying object of the InputText component is Html input text. However, the InputText component contains functionality in addition to rendering an Html input text. This includes associating the InputText with other objects, formatting, validating, and many other things that you cannot find in a mere Html input text.

There is no issue with assigning values directly in your code, and it does not have any disadvantages or security issues. It is just not practical most of the time, as you need to get data from the user and this can only be done via the UI elements on the page.

Related