[英]data comes to controller but not to view
public ActionResult Index()
{
GetEmployee();
return View();
}
private void GetEmployee()
{
SocialMedia item = new SocialMedia();
var employee = _employeeRepository.GetById(Session.GetEmployeeNo());
//employee.No, employee.ManagerNo
item.FirstName = employee.FirstName;
item.LastName = employee.LastName;
item.Departmen = employee.PositionCode;
item.FullName = item.FirstName + " " + item.LastName;
}
还有我的 HTML
@using Models.Model
@model Models.Model.SocialMedia
<div>
@Html.LabelFor(model => model.FullName)
</div>
<div>
@Html.LabelFor(model=>model.Departmen)
</div>
我的结果是
全称部门
姓名,姓氏和部门应该来但没有。 你能帮助我吗
我本来期望的更像是:
public ActionResult Index()
{
var model = GetSocialMedia();
return View(model);
}
private SocialMedia GetSocialMedia()
{
SocialMedia item = new SocialMedia();
var employee = _employeeRepository.GetById(Session.GetEmployeeNo());
//employee.No, employee.ManagerNo
item.FirstName = employee.FirstName;
item.LastName = employee.LastName;
item.Departmen = employee.PositionCode;
item.FullName = item.FirstName + " " + item.LastName;
return item;
}
C# 程序中的数据不会出现在位置 B,因为它是在位置 A 创建的; 它必须肯定被传递,所以它最终会到达预期的位置
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.