Hi @Bryan Valencia ,
Hope the documentation below helps you.
https://www.exceptionnotfound.net/asp-net-mvc-demystified-display-and-editor-templates
https://www.codeguru.com/dotnet/using-display-templates-and-editor-templates-in-asp-net-mvc
https://www.dalsoft.co.uk/blog/index.php/2010/04/26/mvc-2-templates/#Adding_Your_Own_Editor_Template
https://learn.microsoft.com/en-us/aspnet/mvc/overview/getting-started/getting-started-with-ef-using-mvc
According to your example, You don't have to create a custom class for your Editor Template to consume -- just use a string.
You can refer to the following code:
In your model:
public class RegisterModel
{
[Required]
public string UserName { get; set; }
}
And your template would look something like this (be sure to name it "String.cshtml"):
@model System.String
@Html.LabelFor(model => model, (string)ViewData["LabelText"])
@Html.TextBoxFor(model => model)
Then in your view:
@Html.EditorFor(model => model.UserName, new {LabelText = "Test" })
Regarding ValidationMessageFor, this can be added to your template as well:
@Html.ValidationMessageFor(model => model)
Best regards,
Lan Huang
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.