简体   繁体   English

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

[英]passing value from Knockoutjs dropdownlist to SQL MVC5

Ok so I have Kocokout array that is populating a dropdownlist 好的,所以我有填充下拉列表的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));

I have a form with submit button 我有一个带有提交按钮的表格

the drop downs bind to the 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" />

on the count/register controller I have added these to the register model and added them to the new ApplicationUser() 在计数/注册控制器上,我已将它们添加到寄存器模型中并将其添加到新的ApplicationUser()

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

and my registerviewmodel had these added to it 和我的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; }

I know i am missing something that's maybe simple any help would be welcome, PS sorry for my poor English skills 我知道我缺少一些可能很简单的东西,任何帮助都将受到欢迎,PS对不起我的英语能力很差

使用optionsValue绑定到所选项目:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM