这是我尝试插入数据的第一个我自己创建的表。
问题:在我的控制器中,我不确定如何将模型与实际的数据库表链接以执行INSERT
.
同样在该行中,uc.userId = userId;
我收到以下错误:
无效的初始化程序成员声明
我为这个表创建了一个模型:
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()
}
}
谢谢