I have a ViewModel with [Required]
and [MaxLength(4)]
attribute
public class Student
{
[MaxLength(4)]
[Required]
public string Name { get; set; }
}
Inside my view I have
@model List<WebApplication2.Models.Student>
<div class="row">
<div class="col-md-4">
@{
foreach(var item in @Model)
{
@Html.TextBoxFor(model=>item.Name)
@Html.ValidationMessageFor(model => item.Name)
}
}
</div>
<div class="col-md-4">
@{
foreach (var item in @Model)
{
<input type="text" value="@item" />
}
}
</div>
When I use @Html helpers to render text boxes it applied data-validation rules to textbox. I couldn't figure out how I can apply that to normal Html <input type = 'text' />
Is there any way I can do that dynamically without using @Html helpers?