Ответ 1
Это работает из коробки в (по крайней мере) ядро 2.2. В одной из демонстраций они поместили папку EditorTemplates под папкой представлений, а не в общую папку.
Я сам проверил это, используя следующий код...
public class TestEditorForModel
{
[Display(Name = "Testing a string property")]
public string StringProp { get; set; }
[Display(Name = "Testing an integer property")]
[Range(100, 1000)]
public int IntProp { get; set; }
[Display(Name = "Testing a decimal property")]
public decimal DecProp { get; set; }
}
HomeController.cs
public IActionResult Index()
{
return View(new TestEditorForModel
{
StringProp = "testing editorfor",
IntProp = 123,
DecProp = 123.456m
});
}
Главная /EditorTemplates/TestEditorForModel.cshtml
@model TestEditorForModel
<div>
<label asp-for="StringProp"></label>
<input asp-for="StringProp" placeholder="Testing" />
</div>
<div>
<label asp-for="IntProp"></label>
<input asp-for="IntProp" placeholder="123" />
</div>
<div>
<label asp-for="DecProp"></label>
<input asp-for="DecProp" placeholder="100.00" />
</div>
Главная /Index.cshtml
@model TestEditorForModel
@Html.EditorFor(m => m)
Выход