I am performing a user registration, but I am only able to save the Username and Password in the database. How can I save the LastName together?
Below is my controller
with your Actions.
using ProjetoProtocolo_TCC.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;
using WebMatrix.WebData;
namespace ProjetoProtocolo_TCC.Controllers
{
public class ContaController : Controller
{
// GET: Conta
[HttpGet]
public ActionResult Login()
{
return View();
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Login(Login logindata, string ReturnUrl )
{
if (ModelState.IsValid)
{
if (WebSecurity.Login(logindata.NomeUsuario, logindata.Senha))
{
if(ReturnUrl!= null)
{
return Redirect(ReturnUrl);
}
return RedirectToAction("Index", "Home");
}
else
{
ModelState.AddModelError("", "Nome de usuário ou senha inválidos");
return View(logindata);
}
}
ModelState.AddModelError("", "Nome de usuário ou senha inválidos");
return View(logindata);
// return Content(logindata.NomeUsuario + ' ' + logindata.Senha);
}
[HttpGet]
public ActionResult Register()
{
return View();
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Register(Register registerdata, string role)
{
if (ModelState.IsValid)
{
try
{
WebSecurity.CreateUserAndAccount(registerdata.NomeUsuario, registerdata.Senha);
var MINHAVARIAVEL = registerdata.SobrenomeUsuario.ToString();
//{Preciso salvar no banco de dados o valor do sobrenomeUsuario , porem
// o websecurity so permite eu salvar o Username e password , teria algum jeito de salvar
// os demais campos?}
Roles.AddUserToRole(registerdata.NomeUsuario, role);
return RedirectToAction("Index", "Home");
}
catch (MembershipCreateUserException exception )
{
ModelState.AddModelError("", "O Nome de usuário já existe");
return View(registerdata);
}
}
ModelState.AddModelError("", "O Nome de usuário já existe");
return View(registerdata);
// return Content(registerdata.NomeUsuario + ' ' + registerdata.Senha);
}
public ActionResult Logout()
{
WebSecurity.Logout();
return RedirectToAction("Index", "Home");
}
}
}
This is my class that contains the information:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace ProjetoProtocolo_TCC.Models
{
public class Register
{
public string NomeUsuario { get; set; }
public string SobrenomeUsuario { get; set; }
public string Senha { get; set; }
}
}
It's a login code, in which I save the user's name and password, but I need to save more information as a surname, but I'm not able to