Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Put editor templates in view's folder with ASP.NET Core MVC 6

with MVC 4 I was able to put a view's editor templates into the view's folder: AwesomeApp/Views/UserMgmt/EditorTemplates/UserSettings.cshtml.

Now I am using ASP.NET Core MVC 6 and it does not find the editor template. I have to put them into AwesomeApp/Views/Shared/EditorTemplates/UserSettings.cshtml. What needs to be configured so I do not have to put all of my editor templates in this one folder?

I am using the latest version of Telerik's Kendo UI for ASP.NET MVC. But I guess it's something in the application itself.

Best regards, Carsten

like image 359
Carsten Franke Avatar asked Jul 28 '16 14:07

Carsten Franke


1 Answers

This works out of the box in (at least) core 2.2. In one of the demos they have put the EditorTemplates folder underneath a views folder, not the shared folder.

I tested this myself using the following code...

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>

Home/Index.cshtml

@model TestEditorForModel

@Html.EditorFor(m => m)

Output

enter image description here

like image 62
James Sampica Avatar answered Sep 30 '22 16:09

James Sampica