Hi @Kmcnet,
I think I misunderstood your needs in the first place. If you want to dynamically create name and placeholder value for each element.
You can use Html.TextBox instead.
@model List<MvCoreDemo.Models.tbl_Log_FormFields>
<h1>Index</h1>
@for (var i = 0; i < Model.Count(); i++)
{
@Html.TextBox(Model[i].ElementName, Model[i].ElementName, new { id = Model[i].ElementName, placeholder = Model[i].DisplayName })
}
public IActionResult Index()
{
List<tbl_Log_FormFields> formFields = new List<tbl_Log_FormFields>();
formFields.Add(new tbl_Log_FormFields() {
DisplayName = "Display Name",
ElementName = "FirstName" });
return View(formFields);
}
public class tbl_Log_FormFields {
public int ID { get; set; }
public string? DisplayName { get; set; }
public string? ElementName { get; set; }
}
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.