Asp.net-Core-Mvc
使用 ASP.NET Core MVC 6 將編輯器模板放入視圖的文件夾中
使用 MVC 4,我能夠將視圖的編輯器模板放入視圖的文件夾:
AwesomeApp/Views/UserMgmt/EditorTemplates/UserSettings.cshtml.現在我使用的是 ASP.NET Core MVC 6,它沒有找到編輯器模板。我必須將它們放入
AwesomeApp/Views/Shared/EditorTemplates/UserSettings.cshtml. 需要配置什麼,這樣我就不必將所有編輯器模板都放在這個文件夾中?我正在為 ASP.NET MVC 使用 Telerik 的 Kendo UI 的最新版本。但我想這是應用程序本身的東西。
最好的問候,卡斯滕
這在(至少)核心 2.2 中開箱即用。在其中一個展示中,他們將 EditorTemplates 文件夾放在了 views 文件夾下,而不是 shared 文件夾下。
我自己使用以下程式碼對此進行了測試…
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; } }家庭控制器.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)輸出
