I have this model:
public class RecipeDto
{
public int Id { get; set; }
[Required(ErrorMessage = "Title is required")]
public string Title { get; set; }
[Required(ErrorMessage = "Description is required")]
public string Description { get; set; }
[Required(ErrorMessage = "Ingredients are required")]
public List Ingredients { get; set; }
[Required(ErrorMessage = "Directions are required")]
public List Directions { get; set; }
[Range(0, int.MaxValue, ErrorMessage = "Preparation time must be a positive number")]
public int PreparationTimeInMinutes { get; set; }
[Range(0, int.MaxValue, ErrorMessage = "Cooking time must be a positive number")]
public int CookingTimeInMinutes { get; set; }
[Range(0, 20, ErrorMessage = "Servings must be a positive number with 20 as a limit")]
public int Servings { get; set; }
public string ImageUrl { get; set; }
public DateTime CreatedAt { get; set; }
public List Categories { get; set; }
}
I want to create a Razor component to Create a recipe. But don't know which input should I use with the properties of type List
Is it even posible or should I change the type?
On my mind it only comes to use InputText. I will appreciate any advice regarding the CreateRecipe component.
Tuhin PaulPosted Feb 28, 2023, 2:35 AM
Hello Rositsa,
You can use the InputTextArea component to allow users to input a list of strings for the Ingredients and Directions properties. Here's an example implementation of the CreateRecipe component using InputTextArea:
In the above code, there are methods for updating, adding and removing a recipe. There are also methods for adding and removing ingredients and directions from the recipe, as well as removing a category.
Tuhin PaulPosted Mar 26, 2023, 4:58 PM
Using lazy-loading for the categories list, instead of loading all the categories during the component initialization, consider using lazy-loading to load them only when they are needed. This can improve the initial load time of the page and reduce unnecessary network traffic.