If you have unobtrusive check enabled, you can cheat by doing this
@Html.TextBox("name", RunTimeValue, new Dictionary<string, object> { { "data-val", "true" }, { "data-val-required", "The name is required" } })
Other possible data-val values from the window are data-val-regex (with data-val-regex-pattern parameter), data-val-range (with data-val-range-min and data-val-range-max range) , data-val-number and some others that I have not used.
source
share