Select ENUM Tag Helper in ASP.NET Core MVC

五迷三道 提交于 2019-12-05 21:02:00

Finally I found the solution!

It doesn't seem obvious but that way I have no compilation erros. The answer I got from Ivan was not incorrect, but it was necessary to import the CRM.Model on the view like:

@using CRM.Model;

So, my dropdown:

<select asp-for="TipoLog" asp-items="Html.GetEnumSelectList<ETipoLog>()" class="form-control"></select>

You can see, Visual Studio told me it was unessessary, painting it in grey, but without that, I get compilation error. I hope I can help someone else.

Martín La Rosa

You are forgetting to escape the C# code inside the HTML with "@"

Try:

<select asp-for="TipoLog" asp-items="Html.GetEnumSelectList<TipoLog>()"></select>

Updated to remove @ before Html.Get....

Try <select asp-for="TipoLog" asp-items="Html.GetEnumSelectList<ETipoLog>()"></select>

This worked for me, without needing the using declaration.

<select asp-for="ClientFeeStage"
   asp-items="@Html.GetEnumSelectList(typeof(AT.Domain.Entities.ClientFeeStage))"
   class="form-control">
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!