I have only one table for login and registration.
problem is login is not working as well as registration is not work
stanstud.cs
C#
public class stanstuds { [Key] public int id { get; set; } public string fname { get; set; } public string mname { get; set; } public string lname { get; set; } public string country { get; set; } public string usertype { get; set; } public string username { get; set; } public string password { get; set; } }context class
public class stanstudcontext:DbContext { public stanstudcontext():base("cnnos") { } public DbSet studs { get; set; } }
controller
C#
public class LogRegController : Controller { stanstudcontext context = new stanstudcontext(); //admin view just I print the sample message this is an admin view public ActionResult Index() { return View(); } //client view just I print the sample message this is a client view public ActionResult Clientview() { return View(); } //Login [HttpGet] public ActionResult Login() { return View(); } [HttpPost] public ActionResult Login(stanstuds studs) { var userdata=context.studs.Where(x => x.username == studs.username && x.password == studs.password).FirstOrDefault(); if (userdata != null) //when i m debugging this condition is not check { // i have a 2 records of admin in database but when i run time enter that record login is not working if (userdata.usertype == "admin") { return RedirectToAction("Index", "LogReg"); } else { return RedirectToAction("Clientview", "LogReg"); } } else { return View(); } } //Registration public ActionResult Regis() { return View(); } [HttpPost] public ActionResult Regis(stanstuds studs) { context.studs.Add(studs); context.SaveChanges(); return View(); } }Login.cshtml
C#
@model LoginRegOneTable.Models.stanstuds @{ ViewBag.Title = "Login"; } Loginh2> Demo Websitetitle> head> @using (Html.BeginForm()) { UserName:label> @Html.EditorFor(model => model.username) div> Password:label> @Html.EditorFor(model => model.password) div> input type="submit" value="Login" /> div> } body> html>Regis.cshtml
C#
@{ ViewBag.Title = "Regis"; } Regish2> @using (Html.BeginForm()) { @Html.AntiForgeryToken() div class="form-horizontal"> stanstudsh4> hr /> @Html.ValidationSummary(true, "", new { @class = "text-danger" }) div class="form-group"> @Html.LabelFor(model => model.fname, htmlAttributes: new { @class = "control-label col-md-2" }) div class="col-md-10"> @Html.EditorFor(model => model.fname, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(model => model.fname, "", new { @class = "text-danger" }) div> div> div class="form-group"> @Html.LabelFor(model => model.mname, htmlAttributes: new { @class = "control-label col-md-2" }) div class="col-md-10"> @Html.EditorFor(model => model.mname, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(model => model.mname, "", new { @class = "text-danger" }) div> div> div class="form-group"> @Html.LabelFor(model => model.lname, htmlAttributes: new { @class = "control-label col-md-2" }) div class="col-md-10"> @Html.EditorFor(model => model.lname, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(model => model.lname, "", new { @class = "text-danger" }) div> div> div class="form-group"> @Html.LabelFor(model => model.country, htmlAttributes: new { @class = "control-label col-md-2" }) div class="col-md-10"> @Html.EditorFor(model => model.country, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(model => model.country, "", new { @class = "text-danger" }) div> div> **I think the problem is here I want to insert by default entry as a user but how???** div class="form-group"> @Html.LabelFor(model => model.usertype, htmlAttributes: new { @class = "control-label col-md-2" }) div class="col-md-10"> @Html.EditorFor(model => model.usertype, new { htmlAttributes = new { @class = "form-control" ,@value = "User"} }) @Html.ValidationMessageFor(model => model.usertype, "", new { @class = "text-danger" }) div> div> div class="form-group"> @Html.LabelFor(model => model.username, htmlAttributes: new { @class = "control-label col-md-2" }) div class="col-md-10"> @Html.EditorFor(model => model.username, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(model => model.username, "", new { @class = "text-danger" }) div> div> div class="form-group"> @Html.LabelFor(model => model.password, htmlAttributes: new { @class = "control-label col-md-2" }) div class="col-md-10"> @Html.EditorFor(model => model.password, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(model => model.password, "", new { @class = "text-danger" }) div> div> div class="form-group"> div class="col-md-offset-2 col-md-10"> input type="submit" value="Create" class="btn btn-default" /> div> div> div> } @Html.ActionLink("Back to List", "Index") div>
C#
Demo Websitetitle>
head>
@using (Html.BeginForm()){UserName:label>@Html.EditorFor(model => model.username)div>Password:label>@Html.EditorFor(model => model.password)div>input type="submit" value="Login" />div>}body>
html>Regis.cshtml
Regis.cshtml
C#
@{ ViewBag.Title = "Regis"; } Regish2> @using (Html.BeginForm()) { @Html.AntiForgeryToken() div class="form-horizontal"> stanstudsh4> hr /> @Html.ValidationSummary(true, "", new { @class = "text-danger" }) div class="form-group"> @Html.LabelFor(model => model.fname, htmlAttributes: new { @class = "control-label col-md-2" }) div class="col-md-10"> @Html.EditorFor(model => model.fname, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(model => model.fname, "", new { @class = "text-danger" }) div> div> div class="form-group"> @Html.LabelFor(model => model.mname, htmlAttributes: new { @class = "control-label col-md-2" }) div class="col-md-10"> @Html.EditorFor(model => model.mname, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(model => model.mname, "", new { @class = "text-danger" }) div> div> div class="form-group"> @Html.LabelFor(model => model.lname, htmlAttributes: new { @class = "control-label col-md-2" }) div class="col-md-10"> @Html.EditorFor(model => model.lname, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(model => model.lname, "", new { @class = "text-danger" }) div> div> div class="form-group"> @Html.LabelFor(model => model.country, htmlAttributes: new { @class = "control-label col-md-2" }) div class="col-md-10"> @Html.EditorFor(model => model.country, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(model => model.country, "", new { @class = "text-danger" }) div> div> **I think the problem is here I want to insert by default entry as a user but how???** div class="form-group"> @Html.LabelFor(model => model.usertype, htmlAttributes: new { @class = "control-label col-md-2" }) div class="col-md-10"> @Html.EditorFor(model => model.usertype, new { htmlAttributes = new { @class = "form-control" ,@value = "User"} }) @Html.ValidationMessageFor(model => model.usertype, "", new { @class = "text-danger" }) div> div> div class="form-group"> @Html.LabelFor(model => model.username, htmlAttributes: new { @class = "control-label col-md-2" }) div class="col-md-10"> @Html.EditorFor(model => model.username, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(model => model.username, "", new { @class = "text-danger" }) div> div> div class="form-group"> @Html.LabelFor(model => model.password, htmlAttributes: new { @class = "control-label col-md-2" }) div class="col-md-10"> @Html.EditorFor(model => model.password, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(model => model.password, "", new { @class = "text-danger" }) div> div> div class="form-group"> div class="col-md-offset-2 col-md-10"> input type="submit" value="Create" class="btn btn-default" /> div> div> div> } @Html.ActionLink("Back to List", "Index") div> when user registration then insert by default entry as a user my registration is not working when I press register button then the record is not inserted and when I press login then login is not working? something is wrong my script?? please help??

Sanwar RanwaRank #23 · 44.7K reputationPosted Dec 15, 2019, 6:23 PM EST
Ahmed AbdiRank #1,099 · 1.7K reputationPosted Dec 15, 2019, 6:27 PM EST
Rahul Patil196 reputationPosted Dec 15, 2019, 6:32 PM EST
Salman BegRank #284 · 8.8K reputationPosted Dec 15, 2019, 6:40 PM EST
Amit MohantyRank #112 · 20K reputationPosted Dec 15, 2019, 7:23 PM EST
Rahul Patil196 reputationPosted Dec 15, 2019, 8:41 PM EST
Rahul Patil196 reputationPosted Dec 15, 2019, 8:48 PM EST
Amit MohantyRank #112 · 20K reputationPosted Dec 15, 2019, 10:05 PM EST