Combox导致剃刀页面无法渲染

时间:2019-02-17 23:33:29

标签: c# asp.net-core

我应该期望看到一个带有职员记忆表的项目的下拉框,但我的视图无法呈现。这样做的目的是使页面显得破损,我想知道这也是他们获取导致页面无法呈现错误的错误的一种方法。

@model FuelActivityTrackerDal.ViewModels.ActivityEditViewModal
 <div class="container py-5">
 <div class="row">
    <div class="col-md-10 mx-auto">
        <form>
            <div class="form-group row">
                <div class="col-sm-6">
                    <label for="inputFirstname">Activty Name</label>
                    @Html.TextBoxFor(model => model.Name, new { @class = "whatever-class", @cols = 10, @rows = 25 })

                </div>
                <div class="col-sm-3">
                    <label for="inputLastname">Activity Start Date</label>
                        </div>
            </div>
            <div class="form-group row">
                <div class="col-sm-6">
                     @Html.TextAreaFor(model => model.Description, new { @class = "whatever-class", @cols = 10, @rows = 25 })

                </div>
                <div class="col-sm-3">
                    <label for="inputAddressLine2">HoursLeftOnProject </label>
                    <input type="text" class="form-control" id="inputAddressLine2" placeholder="HoursLeftOnProject ">
                </div>
            </div>
            <div class="form-group row">
                <div class="col-sm-6">
                    <label for="inputCity">Status </label>
                    <input type="text" class="form-control" id="inputCity" placeholder="Status ">
                </div>
                <div class="col-sm-3">
                    <label for="inputState">ActivityType </label>
                    <input type="text" class="form-control" id="inputState" placeholder="ActivityType ">
                </div>
                <div class="col-sm-3">
                    <label for="inputPostalCode">SOP</label>
                    <div class="form-group">
                        @Html.LabelFor(x => Model.StaffID, htmlAttributes: new { @class = "control-label col-md-2" })
                        <div class="col-md-5">
                            <div class="form-group">
                                @Html.LabelFor(x => Model.StaffID, htmlAttributes: new { @class = "control-label col-md-2" })
                                <div class="col-md-5">
                                    @Html.DropDownListFor(x => Model.StaffID, new SelectList(Model.StaffMemmbers, "Value", "Text"), htmlAttributes: new { @class = "form-control", @id = "Region" })
                                    @Html.ValidationMessageFor(x => x.StaffID, "", new { @class = "text-danger" })
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                </div>

            <button type="button" class="btn btn-primary px-4 float-right">Save</button>
            <button type="button" class="btn btn-primary px-4 float-right">Cancel</button>
        </form>
    </div>
</div>
</div>

但是我正在使用ActivityEditViewModal填充视图。

 public   class ActivityEditViewModal
 {
    public  int ActivityHeaderId { get; set; } //(int, null)
    public DateTime? ActivityDate { get; set; } //(date, null)
    public string Name { get; set; } //(nvarchar(350), null)
    public DateTime? ActivityEndDate { get; set; } //(datetime, null)
    public string Description { get; set; } //(nvarchar(max), null)
    public int? ActivityLinesId { get; set; } //(int, null)
    public int? HoursLeftOnProject { get; set; } //(time(7), null)
    public int Status { get; set; } //(nchar(10), null)
    public int ActivityType { get; set; } //(int, null)
    public DateTime? CreatedDate { get; set; } //(date, null)
    public string CreatedBy { get; set; } //(nvarchar(50), null)
    public bool? isActive { get; set; } //(bit, null)
    public bool? isDeleted { get; set; } //(bit, null)
    public bool? isArchived { get; set; } //(bit, null)
    public int? SOP { get; set; } //(nvarchar(50), null)
    public int? DepartmentId { get; set; } //(int, null)
    public string EmployeeName { get; set; } //(nvarchar(301), null)


    public string StaffName { get; set; }        
    public int StaffID { get; set; }       
    public IEnumerable<SelectListItem> StaffMemmbers { get; set; }


}

在“活动回购”中,我正在填充工作人员,您可以从屏幕截图中看到他们正在工作。

 public List<ActivityEditViewModal> GetAllActivites()
 {
        var staffRepo = new StaffRepositry(_db);

        List<ActivityHeader> activity = new List<ActivityHeader>();
            activity = _db.ActivityHeader.AsNoTracking()
                .Include(x => x.StaffMembers)
                .ToList();

            if (activity != null)
            {
                List<ActivityEditViewModal> activityDisplay = new List<ActivityEditViewModal>();
                foreach (var x in activity)
                {
                    var customerDisplay = new ActivityEditViewModal()
                    {

                        ActivityHeaderId = x.ActivityHeaderId,
                        ActivityDate =x.ActivityDate,
                        Name=x.Name,
                        ActivityEndDate = x.ActivityEndDate,
                        Description = x.Description,
                        StaffID =(int)x.StaffId




                    };
                customerDisplay.StaffMemmbers = staffRepo.GetStaffs();
                activityDisplay.Add(customerDisplay);


                }
                return activityDisplay;
            }
      return null;
   }

public IEnumerable<SelectListItem> GetStaffs()
{   
   List<SelectListItem> staff = _db.Staff
                .OrderBy(n => n.FirstName)
                    .Select(n =>
                    new SelectListItem
                    {
                        Value = n.StaffID.ToString(),
                        Text = n.FirstName + " " + n.LastName
                    }).ToList();
            var staffip = new SelectListItem()
            {
                Value = null,
                Text = "--- select staff ---"
            };
            staff.Insert(0, staffip);
            return new SelectList(staff, "Value", "Text");
        }
    }

enter image description here

结果是完整的损坏页面。当我取出下拉菜单的代码时,它可以正常工作。

0 个答案:

没有答案