これは、私がデータを挿入しようとしている、自分で作成した最初のテーブルです。
質問:私のコントローラーでは、モデルを実際のデータベーステーブルにリンクしてを実行する方法がわかりませんINSERT
。
また、この行uc.userId = userId;
で次のエラーが発生しています。
無効な初期化メンバーdeclarato
このテーブルのモデルを作成しました。
public class RegisterModel
{
public bool isCertified { get; set; }
public int certType { get; set; }
public string identifier { get; set; }
}
意見:
<tr>
<td style="font-size:10px;">Habilitar Login com Cert. Digital:</td>
<td>@Html.CheckBoxFor(m => m.isCertified)</td>
</tr>
<div id="certDigitalBlock">
<tr>
<td class="smallField">Tipo do Certificado:</td>
<td>@Html.DropDownListFor(m => m.certType, new SelectList(ViewBag.certType, "id","type"))</td>
</tr>
<tr>
<td>Identificação:</td>
<td>@Html.TextBoxFor(m => m.identifier, new { @class = "validate[required]" }) @Html.ValidationMessage("awnserVal", "*")</td>
</tr>
</table>
コントローラ
using (tgpwebgedEntities context = new tgpwebgedEntities())
{
var userID = from u in context.aspnet_Users where u.UserName == model.UserName select u.UserId;
if (checkIsCertified == true)
{
UsersCertified uc = new UsersCertified {
uc.userId = userId;
uc.certTypeId = model.certType;
uc.keyNumber = model.identifier;
}
context.SaveChanges()
}
}
ありがとう