当我创建角色时,我只能传递一个参数RoleName
。如果我传递多个参数,则显示错误。如何传递多个参数来插入表。
[HttpPost]
[MyExceptionHandler]
[ValidateAntiForgeryToken]
public ActionResult RoleCreate([Bind(Include = "RoleName,Status,CreatedBy,CreatedDate,ModifiedBy,ModifiedDate")]Role role)
{
if (ModelState.IsValid)
{
if (Roles.RoleExists(role.RoleName))
{
ModelState.AddModelError("Error", "Rolename already exists");
return View(role);
}
else
{
Roles.CreateRole(role.RoleName, role.Status,role.CreatedBy,role.CreatedDate,role.ModifiedBy,role.ModifiedDate);
return RedirectToAction("ViewRole", "Account");
}
}
else
{
ModelState.AddModelError("Error", "Please enter Username and Password");
}
return View(role);
}
如果我添加Roles.CreateRole(role.RoleName, role.Status,role.CreatedBy,role.CreatedDate,role.ModifiedBy,role.ModifiedDate);
多个参数显示错误
答案 0 :(得分:1)
假设您具有枚举角色。唯一的方法是。
foreach (Role role in Enum.GetValues(typeof(Role)))
{
Roles.CreateRole(role);
}
根据MSDS CreateRole Method (String)
只接受一个参数。它没有过载。
https://msdn.microsoft.com/en-us/library/system.web.security.roles.createrole(v=vs.110).aspx