Registration Form in MVC

Code

  [Route("CreateNewAccount")]
        [HttpGet]

        public ActionResult CreateAccount()
        {
            return View();
        }

        [Route("CreateNewAccount")]
        [HttpPost]

        public ActionResult CreateAccount(MyLogin log)
        {
            tbl_Login tb = new tbl_Login() //table 
            {
                FirstName = log.FirstName,
                Userid=log.Userid,
                password=log.password,
                Copassword=log.Copassword,
            };
            FormDbEntities db = new FormDbEntities();
            db.tbl_Login.Add(tb);
           int a= db.SaveChanges();
            if(a==1)// send Data in Login page using Sesstion
            {
                Session["data"]  = "Welcome in new account" +"  "+ tb.FirstName.ToString();
                return RedirectToAction("Login");
               
            }
            else
            {
                ViewBag.alert = "<script>alert('Account Creation Fail')</script>";
                ViewData["Greteuser"] = "Welcome in new account" + tb.FirstName.ToString();
            }
            return View();
        }




CsHTML


@model Test.Models.MyLogin

@{
    ViewBag.Title = "CreateAccount";
}

@ViewData["CreateAccFailer"];
<h2 style="color:white">Create New Account</h2>
<div class="container mainsign " id="sig">
    @using (Html.BeginForm())
    {
        @Html.AntiForgeryToken()

        <div class="form-horizontal">
            
            <hr />
            @Html.ValidationSummary(true, "", new { @class = "text-danger" })
            <div class="form-group">
                @Html.LabelFor(model => model.FirstName, htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.EditorFor(model => model.FirstName, new { htmlAttributes = new { @class = "form-control" } })
                    @Html.ValidationMessageFor(model => model.FirstName, "", new { @class = "text-danger" })
                </div>
            </div>

            <div class="form-group">
                @Html.LabelFor(model => model.Userid, htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.EditorFor(model => model.Userid, new { htmlAttributes = new { @class = "form-control" } })
                    @Html.ValidationMessageFor(model => model.Userid, "", 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">
                @Html.LabelFor(model => model.Copassword, htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.EditorFor(model => model.Copassword, new { htmlAttributes = new { @class = "form-control" } })
                    @Html.ValidationMessageFor(model => model.Copassword, "", new { @class = "text-danger" })
                </div>
            </div>

            <div class="form-group">
                @Html.LabelFor(model => model.Contactno, htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.EditorFor(model => model.Contactno, new { htmlAttributes = new { @class = "form-control" } })
                    @Html.ValidationMessageFor(model => model.Contactno, "", 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>

    }
</div>

<link href="~/Content/CreatenewAccount.css" rel="stylesheet" />

Comments

Popular posts from this blog

Search Record From Table Using jQuery in Asp.net core MVC

How To insert Radio Button Data in DataBase -- MVC

Toolbox Webparts Controls