我正在尝试通过此表单将一些数据发送到数据库。我不断收到有关具有相同键的项目的错误。
我已经尝试调试此错误已有一段时间了。我确实有几个元素被其@Html帮助器分配了相同的名称,但我想我已经将它们清除了。
<set-variable name="rawValue" value="@(context.Request.Body.As<JObject>()["date"].ToString())" />
保存用户
<div id="addNewUser" class="newUser" style="border: solid black 2px">
<form name="newUser" method="post" action="@Url.Action("Submit", "Roles")">
<h4>Add New User</h4>
<div style="display: flex; justify-content: space-between">
<div id="ddlNewUserHealthPlan" class="form-group">
@Html.DropDownListFor(m => m.NewUserHealthPlans, (IEnumerable<SelectListItem>)Model.GetHealthPlans(Model.HEALTHPLAN), "Select a Healthplan", new { @class = "form-group", @id = "ddlNewUserHealthPlanSelect" })
</div>
<div id="ddlNewUserRoles" class="form-group">
@Html.DropDownListFor(m => m.Roles, (IEnumerable<SelectListItem>)Model.GetUserRoles(Model.USERROLE), "Select a Role", new { @class = "form-group", @id = "ddlNewUserRoleSelect" })
</div>
</div>
<div style="display: flex; justify-content: space-between">
<div class="form-group">
@Html.Label("User Id: ")
@Html.TextBoxFor(m => m.User_Id, new { @class = "form-control" })
</div>
<div id="ddlNewUserPrimaryHP" class="form-group">
@Html.DropDownListFor(m => m.NewUserPrimaryHealthPlan, (IEnumerable<SelectListItem>)Model.GetHealthPlans(Model.HEALTHPLAN), "Select a Primary Healthplan", new { @class = "form-group", @id = "newUserPrimaryHP" })
</div>
</div>
<br />
<div style="display: flex; justify-content:center">
<button type="submit" class="btn btn-primary">Add new User</button>
</div>
</form>
</div>
堆栈跟踪
public void SaveUser(SearchRolesViewModel objSearchRolesViewModel, string userID)
{
USERACCOUNT objUserAccount = new USERACCOUNT
{
HPID = Convert.ToInt32(objSearchRolesViewModel.NewUserHealthPlans),
DOMAIN = "Aeth",
NTUSERID = objSearchRolesViewModel.User_Id,
ROLEID = Convert.ToInt32(objSearchRolesViewModel.UserRole),
FIRSTNAME = "Matthew",
LASTNAME = "Wright",
EMAIL = "MW@test.com",
ACTIVE = Convert.ToBoolean(objSearchRolesViewModel.ActiveStatus),
DEFAULTPLANID = Convert.ToInt32(objSearchRolesViewModel.NewUserPrimaryHealthPlan),
CREATEID = userID,
CREATEDATE = DateTime.Now,
UPDATEID = userID,
UPDATEDATE = DateTime.Now
};
_context.USERACCOUNTs.Add(objUserAccount);
_context.SaveChanges();
}
谢谢!