This is the first table created on my own that I am trying to insert data.
Question: in my controller, I am not sure how to link the model with the actual database table to perform the INSERT.
Also in the line uc.userId = userId; I am getting the following error:
Invalid initializer member declarato
I created a model for this table:
public class RegisterModel
{
public bool isCertified { get; set; }
public int certType { get; set; }
public string identifier { get; set; }
}
View:
<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>
Controller
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()
}
}
Thanks
Shouldn’t be written under brackets? if you are using a constructor.
Add this code: