0

我是 MVC 的初学者。如果有人可以帮助我,请!

在我看来,我有以下看法

<div class="form_group">
        @Html.LabelFor(m => m.Time)
        @Html.DropDownListFor(m=>m.Genre, new SelectList(Model.Genres, "Id", "Type"), "", new { @class = "form-control" })

    </div>

我有以下视图模型

public class GigsFormViewModel
    {
        public string Venue { get; set; }
        public string Date { get; set; } 
        public string Time { get; set; }
        public IEnumerable<Genre> Genres { get; set; }
        public int Genre;
    }

当我按下提交按钮时,我没有在控制器中获得选定的流派 id(即 GigsFormViewModel.Genre 始终为 0)

然而,日期、时间和地点越来越多。

以下是我的控制器的外观。

[HttpPost]
        public ActionResult Create(GigsFormViewModel gvm)
        { 
             var venue = gvm.Venue ;//This got entered value
             int genre = gvm.Genre ; //This is always 0
    }

我错过了什么?我很感激你试图帮助我。

谢谢古鲁马尔。

4

1 回答 1

0
public class GigsFormViewModel
    {
        public string Venue { get; set; }
        public string Date { get; set; } 
        public string Time { get; set; }
        public IEnumerable<Genre> Genres { get; set; }
        *public int Genre{ get; set; }*
    }

我需要将 Genre 设为属性!

于 2018-12-28T10:19:16.777 回答