gpt4 book ai didi

c# - 不存在具有键 'IEnumerable' 的 'x' 类型的 ViewData 项。'

转载 作者:太空宇宙 更新时间:2023-11-03 14:56:55 25 4
gpt4 key购买 nike

<分区>

在我看来我有一个问题,我的下拉列表失败并且不起作用不知道为什么

@model DigikalaHR.View_Model.Entitys.Member
.
.
.
.
<div class="form-group">
@Html.LabelFor(model => model.TeamId, "TeamId", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownList("TeamId",null,htmlAttributes: new {@clas="form-control" })
@Html.ValidationMessageFor(model => model.TeamId, "", new { @class = "text-danger" })
</div>
</div>

在这段代码中,这是我得到的错误

There is no ViewData item of type 'IEnumerable' that has the key 'TeamId'.'

如果我把代码改成这个

@Html.DropDownList("TeamId",model=>model.TeamId,htmlAttributes: new {@clas="form-control" })

这是我收到的错误

Cannot convert lambda expression to type 'IEnumerable' because it is not a delegate type

这也是我在 Controller 中的 Create 方法

  #region [- Create() -]

#region [- Get -]
public ActionResult Create()
{
return View();
}
#endregion

#region [- Post -]
// POST: Member/Create
[ValidateAntiForgeryToken]
[HttpPost]
public ActionResult Create(string _fName, string _lName, string _describtion, string _pic, int _teamId, int _positionId)
{
try
{
// TODO: Add insert logic here
Ref_Member = new View_Model.Buisiness.Member();
//Ref_Member.CreateMember();
return RedirectToAction("Index");
}
catch
{
return View();
}
}

这是我传递到 View 中的 View 模型

  #region [- Id -]
[ScaffoldColumn(true)]
[DisplayName("شماره")]
public int Id { get; set; }
#endregion

#region [- FName -]
[DisplayName("نام")]
[Required(ErrorMessageResourceType = typeof(Resources.Messages), ErrorMessageResourceName = "Required")]
[StringLength(100, ErrorMessageResourceType = typeof(Resources.Messages), ErrorMessageResourceName = "StringLength")]
public string FirstName { get; set; }
#endregion

#region [- LName -]
[DisplayName("نام خانوادگی ")]
[Required(ErrorMessageResourceType = typeof(Resources.Messages), ErrorMessageResourceName = "Required")]
[StringLength(100, ErrorMessageResourceType = typeof(Resources.Messages), ErrorMessageResourceName = "StringLength")]
public string LastName { get; set; }
#endregion

#region [- Describtion -]
[DataType(DataType.MultilineText)]
[DisplayName("توضیحات")]
public string Description { get; set; }
#endregion

#region [- Pic -]
[DisplayName("عکس")]
[Required(AllowEmptyStrings =false,ErrorMessageResourceType =typeof(Resources.Messages), ErrorMessageResourceName = "Required")]
public string Pic { get; set; }
#endregion

#region [- TeamId -]
[DisplayName("شماره تیم")]
public Nullable<int> TeamId { get; set; }
#endregion

#region [- PositionId -]
[DisplayName("شماره سرپرست")]
public int PositionId { get; set; }

#endregion

#region [- Departments -]
[DisplayName("دپارتمان")]
public ICollection<Department> Departments { get; set; }
#endregion

public Position Position { get; set; }
public Team Team { get; set; }

public ICollection<Team> Teams { get; set; }
}

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com