[英]Html.EditorFor set initial value of textbox
Binding to a view model in MVC3, using C#. 使用C#绑定到MVC3中的视图模型。
Having difficulty setting the initial value of the textbox, trying to do so without having to create a template etc 难以设置文本框的初始值,无需创建模板等即可尝试这样做
Any ideas or do I have to go down the path of creating a customn template? 有什么想法还是我必须沿着创建定制模板的道路走下去?
Thanks, Tim 蒂姆,谢谢
You could set initial values in the controller: 您可以在控制器中设置初始值:
public ActionResult Index()
{
var model = new MyViewModel
{
MyProperty = "initial value"
};
return View(model);
}
and in the view: 并在视图中:
@model MyViewModel
@Html.EditorFor(x => x.MyProperty)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.