DropDownListFor Razor with List <string>

时间:2016-06-28 17:32:00

标签: asp.net-mvc razor

config.paperclip_defaults = {
  storage: :s3,
  s3_credentials: {
    bucket: ENV.fetch('S3_BUCKET_NAME'),
    access_key_id: ENV.fetch('AWS_ACCESS_KEY_ID'),
    secret_access_key: ENV.fetch('AWS_SECRET_ACCESS_KEY'),
    s3_region: ENV.fetch('AWS_REGION'),
  }
}

Profils =字符串列表

SelectedProfil = string

在帖子

上,SelectedProfil对于控制器始终为空

1 个答案:

答案 0 :(得分:0)

简单地

using (Html.BeginForm("Add", "Test", FormMethod.Post))

@Html.DropDownList("profil", new SelectList(Model.Profils.Select(x => new { Value = x, Text = x }),"Value","Text")))

[HttpPost]
public ActionResult Add(string profil)
{
   ....
}