Can I pass ModelExpression to TagHelper?

We can get ModelExpressionusing this property in TagHelper:

[HtmlAttributeName("asp-for")]
public ModelExpression For { get; set; }

I somehow managed * with ViewModel, which has a property ModelExpression:

public class TemplateViewModel
{
    public ModelExpression For { get; set; }
}

Every time I try to pass it, the Model expression is Forfrom TemplateViewModel, and not the real expression, which is stored in For:

@model TemplateViewModel
<input asp-for="@Model.For" class="form-control"/>

The above results:

<input class="form-control" type="text" id="For" name="For" value="Microsoft.AspNetCore.Mvc.ViewFeatures.ModelExpression" />

I expected the input that is being described ModelExpressioninstead of literaly a ModelExpressionfor ModelExpression.

*, since I want to have a template view for TagHelper using IHtmlHelper::PartialView(). This example is greatly minimized. My main motivation is to create a single <form-group for="" />TagHelper that the Bootstrap Forms Group generates .

+4

Source: https://habr.com/ru/post/1688766/


All Articles