我在创建视图中填充文本框时遇到问题。相关代码如下。
模型:
public class Client
{
public int ClientID { get; set; }
private string _username = HttpContext.Current.User.Identity.Name;
public string UserName
{
get
{ return _username; }
set
{ _username = value;}
}
}
看法:
@model model.Client
<div class="editor-label">
@Html.LabelFor(model => model.UserName)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.UserName)
@Html.ValidationMessageFor(model => model.UserName)
</div>
控制器:
public ActionResult Create()
{
return View(new Client());
}
这在 IE 和 Firefox 中完美运行;文本框以<input>
设置为当前用户登录名的值呈现。然而,在 Chrome 中,该值是一个空字符串。
谁能解释这种行为并提供解决方法?
提前感谢您的任何帮助。