在ASP.NET MVC中,可以通过JavaScript的OnChange事件来更新TextBoxFor的值。以下是一个包含代码示例的解决方法:
@Html.TextBoxFor(m => m.TextBoxValue, new { id = "textBoxValue" })
function updateTextBoxValue() {
var inputTextValue = document.getElementById("inputText").value;
document.getElementById("textBoxValue").value = inputTextValue;
}
public ActionResult Index()
{
var model = new YourModel();
return View(model);
}
[HttpPost]
public ActionResult Index(YourModel model)
{
return View(model);
}
这样,当你在文本框中输入内容并离开文本框时,TextBoxFor的值将会被更新为文本框的值。