我有一个控制器,我可以使用ViewBag将一些数据发送到View:
public ActionResult Index()
{
string us = Request.LogonUserIdentity.Name.Substring(Request.LogonUserIdentity.Name.LastIndexOf(@"\") + 1);
var user = unitOfWork.userRepository.Get().Where(w => w.Login == us).Select(s => new { credentials=s.Name+" "+s.Surname}).FirstOrDefault();
ViewBag.user = user.credentials.ToString();
return View();
}
此数据用于填充此隐藏字段:
@Html.Hidden("user", (object)ViewBag.user, new { data_bind = "value:requestingPerson" })
这是绑定到:
var ViewModel = function () {
var self = this;
self.requestingPerson = ko.observable();
}
但它呈现为:
<input data-bind="value:requestingPerson" id="user" name="user" type="hidden" value="">
没有价值。 有没有办法解决它?