Currently working on a project where I am trying my best to avoid any C# in a code block on the razor file so I'm trying to follow the MVVM design pattern. I have a test viewmodel that is just trying to get a string value from the tag markup.
ViewModel
public class MyViewModel : NotifiableAndDisposableBase
{
[Parameter]
public string Text { get; set; }
}
MyCard Component
@inject MyViewModel vm
<h3 style="color: white">MyCard</h3>
<h3 style="color: white">@vm.Text</h3>
View
<div>
<MyCard Text="This is passed in"/>
</div>
Now, this code will not work the Text parameter will not be recognized in the tag call. The only way I CAN get a parameter to be recognized and passed is if I use a @Code block like so
@code{
[Parameter]
public string CodeBlockText {get; set;}
}
OR
Instead of my component using [Inject] my viewmodel it [Inherits] my viewmodel, but using Inherits means I have to use the Default constructor, but I need to use the persistent HttpClient that was created in the StartUp.cs
I figured a work around would be to create a parameter in the code block then set the actual property in the view model, but I'm not sure if that's good practice.
Any suggestions would be appreciated.