I want wrap this:
<textarea asp-for="@Model.Content" ...>
into reusable ViewComponent, where property will be parameter:
<vc:editor asp-for="@Model.Content" />
I was able to pass asp-for as parameter to the viewcomponent:
public class EditorViewComponent : ViewComponent
{
public IViewComponentResult Invoke(ModelExpression aspFor = null)
{
//when debugging, aspFor has correct value
return View(aspFor);
}
}
But I'm not able to evaluate it in component's view. This does not work:
<!-- ViewComponents/Editor/Default.cshtml -->
@model Microsoft.AspNetCore.Mvc.ViewFeatures.ModelExpression
<textarea asp-for="@Model" />
Any ideas?
ViewComponents
andTagHelpers
. learn.microsoft.com/en-us/aspnet/core/mvc/views/view-components – Llanes