In MVC, we use View Model to bind the values to the view like I am using Razor view engine syntax below:-
@Html.TextBoxFor(m=>m.ValueForTextBox)
@Html.ValidationFor(m=>m.ValueForTextBox)
public ActionResult GetValueForTextBox()
{
var viewModel = new ValueForTextBoxViewModel
{
ValueForTextbox = "Fetch and assign the value here"
}
return View(viewModel);
}
public class ValueForTextBoxViewModel
{
[Required("Required Field")]
public string ValueForTextbox {get; set;}
}
Hope this helps anyway
Thanks
:)