【问题标题】:数据到达控制器但不查看
【发布时间】:2022-01-23 11:38:21
【问题描述】:
 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>

我的结果是

全名 部门

姓名,姓氏和部门应该来但没有。 你能帮我吗

【问题讨论】:

  • 您的数据永远不会从 GetEmployee() 方法中暴露出来。该方法可能需要有一个返回值,您需要将它传递给 View() 方法

标签: javascript c# html css asp.net


【解决方案1】:

我本以为会是这样的:

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 中创建的;它必须肯定被传递,所以它最终会到达预期的位置

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-22
    相关资源
    最近更新 更多