This is somehow related to The Question
I am using jquery unobtrusive validation. I have the following model
public class MyModel
{
[Required]
public int ID { get; set; }
[MinLength(2)]
public string Description { get; set; }
}
I want to generate an html markup with validation(This is what I want to generate my self using code)
<input class="FormElement form-control valid" type="text" data-val="true" data-val-required="The ID field is required." id="ID" name="ID">
<input class="FormElement form-control valid" type="text" data-val="true" data-val-minlength="The field Description must be a string or array type with a minimum length of '2'." data-val-minlength-min="2" id="Description" name="Description" value="description changed 6">
My question is how Can I manually generate the markup from the model attributes inside my controller.
So My code will simply look like this
private readonly IHtmlGenerator htmlGenerator;
private readonly IHtmlHelper helper;
public MyController(IHtmlGenerator htmlGenerator, IHtmlHelper hh)
{
if (htmlGenerator == null)
throw new ArgumentNullException("htmlGenerator");
this.htmlGenerator = htmlGenerator;
this.helper = hh;
}
public IActionResult GenerateHtml()
{
HtmlHelper tempHelper= this.HtmlHelper;
// Generate the markup for ID and Description here from model MyModel(With VALIDATION)
}