从Knockoutjs下拉列表传递值到SQL MVC5



现在我有了一个填充下拉列表的Kocokout数组

var idDDL = (from c in db.IDLists select new ID { ID = c.ID, ID = c.ID}).ToArray();
var IDList = Html.Raw(JsonConvert.SerializeObject(ViewBag.idDDL));
我有一个带有提交按钮的表单

下拉列表绑定到select。

<div class="form-group" style="padding-top: 0px">
        @Html.LabelFor(m => m.ID, new { @class = "col-md-2 control-label" })
        <div class="col-md-10">
            <select id="idDDL" data-bind="options: list, optionsText: 'ID'"></select>
        </div>
    </div>
<input type="submit" class="btn btn-default" value="Create" />

在计数/寄存器控制器上,我将这些添加到寄存器模型中,并将它们添加到新的ApplicationUser()

var user = new ApplicationUser() { UserName = model.Email, Email = model.Email, ClubType = model.ClubType, UserAuthorityLevel = model.AuthType, ClubID = model.ClubID };

和我的registerviewmodel添加了这些

    [Display(Name = "ID")]
    public string ID { get; set; }
    [Display(Name = "Type ")]
    public string Type { get; set; }
    [Display(Name = "Authority Level ")]
    public string AuthType { get; set; }

我知道我错过了一些东西,可能是简单的任何帮助将是受欢迎的,PS抱歉我的英语水平差

使用optionsValue绑定所选项目:

<select id="idDDL" data-bind="options: list, optionsText: 'ID', optionsValue: 'SelectedID'"></select>

最新更新