在MVC4中,我能够将视图的编辑器模板放入视图的文件夹:AwesomeApp/Views/UserMgmt/EditorTemplates/UserSettings.cshtml
。
现在我使用的是ASP.NET CoreMVC6,但它找不到编辑器模板。我必须把它们放到AwesomeApp/Views/Shared/EditorTemplates/UserSettings.cshtml
中。需要配置什么才能使我不必将所有编辑器模板都放在这个文件夹中?
我使用的是用于ASP.NET MVC的Telerik的Kendo UI的最新版本。但我猜这是应用程序本身的一些东西。
致以最好的问候,卡斯汀
发布于 2019-08-20 21:28:41
这在(至少)核心2.2中是开箱即用的。在one of the demos中,他们将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
});
}
Home/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)
输出
https://stackoverflow.com/questions/38639315
复制相似问题