将值从Knockoutjs下拉列表传递给SQL MVC5

时间:2014-06-18 14:32:07

标签: c# javascript asp.net sql knockout.js

好的,所以我有一个填充下拉列表的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));

我有一个带提交按钮的表单

下拉列表绑定到选择。

<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抱歉我的英语能力差

1 个答案:

答案 0 :(得分:0)

使用optionsValue绑定到所选项目:

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