MVC将变量HTML从表单发送到数据库

时间:2015-07-31 08:11:43

标签: html forms model-view-controller

所以我有下一个问题,我想从视图发送变量到数据库,我成功但我不能从select发送..我可以发送姓氏名字和技能但是当我发送团队时它来了null ..

<form id="addPlayerForm" action="#">
    <br>
    <input type="text" id="txtSurname" name="player_surname">
    <br>
    <br>
    <input type="text" id="txtFirstname" name="player_firstname">
    <br />
   SKILL:
    <br>
    <input type="number" id="txtSkill" name="player_skill" />
    <br />
    <br>
    <select>
        <option selected="selected" value="0">no</option>
        @foreach(var teamInfo in Model.Teams)
        {
            <option value="@teamInfo.Key" name="id_team">@teamInfo.Value</option>
        }
    </select>
    <br>
    <p>
        <input id="addPlayerButton" type="button" value="Save" />
    </p>
</form>

这里我从我的模型解析到我的数据库模型..

  public players MapPlayerFromForm(PlayerModel formPlayer)
       {
            var toRet = new players
                {
                 player_firstname=formPlayer.player_firstname,
                  player_surname=formPlayer.player_surname,
                 player_skill=formPlayer.player_skill,
                id_team=formPlayer.teams.id_team

        };
        return toRet;

    }

0 个答案:

没有答案