Drop down menu 填充DropDownListFor,默认值为guid参数

Drop down menu 填充DropDownListFor,默认值为guid参数,drop-down-menu,asp.net-mvc-5,guid,html.dropdownlistfor,Drop Down Menu,Asp.net Mvc 5,Guid,Html.dropdownlistfor,我已经用所有正确的值填充了DropDownList for。我正在传递Guid参数,但不知道如何将默认值设置为该Guid 查看 <div class="form-group"> @Html.LabelFor(model => model.Parent) @Html.DropDownListFor(model => model.Parent, new SelectList(Model.AllParents, "Id", "Name"), string.Empty,

我已经用所有正确的值填充了DropDownList for。我正在传递Guid参数,但不知道如何将默认值设置为该Guid

查看

<div class="form-group">
  @Html.LabelFor(model => model.Parent)
  @Html.DropDownListFor(model => model.Parent, new SelectList(Model.AllParents, "Id", "Name"), string.Empty, new { @class = "form-control" })
  @Html.ValidationMessageFor(model => model.Parent)
</div>

您需要将string.Empty替换为“您想要的默认值”


您需要将
string.Empty
替换为“Default value do you want”
@Html.DropDownListFor(model=>model.Parent,new SelectList(model.AllParents,“Id”,“Name”),“Default value is here”,new{@class=“form control”})
gez…完全忽略了这一点。复制并粘贴答案,这样我就可以给你评分了。谢谢
public class ParentViewModel
{
     public List<Parent> AllParents { get; set; }

     [DisplayName("Parent")]
     public Guid? ParentId { get; set; }

}
[HttpGet]
public ActionResult Create(Guid? id)
{

            var parentViewModel = new ParentViewModel
            {
                AllParents = _Service.GetAll().ToList()
            };
            return View(parentViewModel);
        }
    }
@Html.DropDownListFor(model => model.Parent, new SelectList(Model.AllParents, "Id", "Name"), "Default value is here here", new { @class = "form-control" })