locked
Simple Register page unable to post RRS feed

  • Question

  • User-1256377279 posted

    Hi Guys,

    I have simple register page and unable to save to db using ASP.NET core MVC, below is my code

      [HttpPost]
            public IActionResult Index(Registration registration)
            {
                if(ModelState.IsValid)
                {
                    _context.Registration.Add(registration);
                    _context.SaveChanges();
                }
                return View(registration);
            }
    
    @model GOMLIB.Models.Registration
    
    <div class="row">
    
        <div class="col-xl-12">
            <div class="card">
                <div class="card-body">
    
                    <h4 class="header-title text-yellow">REGISTER WITH US</h4>
                    @*<p class="sub-header">
                            Easily extend form controls by adding text, buttons, or button groups on either side of textual inputs, custom selects, and custom file inputs
                        </p>*@
    
                    @using (Html.BeginForm())
                    {
                        <div class="form-group mb-1 mt-3">
    
                            <div class="input-group">
                                <input type="email" class="form-control" placeholder="Enter email address" required parsley-type="email" aria-label="Enter email address">
                                <div class="input-group-append">
                                    <input class="btn btn-info waves-effect waves-light" type="submit" value="Register" />
                                </div>
                            </div>
                        </div>
                    }
                </div>
            </div>
        </div>
    
    
    </div>
    
    using System;
    using System.Collections.Generic;
    using System.Text;
    
    namespace GOMLIB.Models
    {
        public partial class Registration
        {        
            public int Registrationid { get; set; }
            public string Email { get; set; }
            public DateTime Createddate { get; set; }
        }
    }
    

    Thanks,

    Shabbir

    Monday, May 4, 2020 9:46 AM

All replies

  • User475983607 posted

    Hi Guys,

    I have simple register page and unable to save to db using ASP.NET core MVC, below is my code

      [HttpPost]
            public IActionResult Index(Registration registration)
            {
                if(ModelState.IsValid)
                {
                    _context.Registration.Add(registration);
                    _context.SaveChanges();
                }
                return View(registration);
            }
    @model GOMLIB.Models.Registration
    
    <div class="row">
    
        <div class="col-xl-12">
            <div class="card">
                <div class="card-body">
    
                    <h4 class="header-title text-yellow">REGISTER WITH US</h4>
                    @*<p class="sub-header">
                            Easily extend form controls by adding text, buttons, or button groups on either side of textual inputs, custom selects, and custom file inputs
                        </p>*@
    
                    @using (Html.BeginForm())
                    {
                        <div class="form-group mb-1 mt-3">
    
                            <div class="input-group">
                                <input type="email" class="form-control" placeholder="Enter email address" required parsley-type="email" aria-label="Enter email address">
                                <div class="input-group-append">
                                    <input class="btn btn-info waves-effect waves-light" type="submit" value="Register" />
                                </div>
                            </div>
                        </div>
                    }
                </div>
            </div>
        </div>
    
    
    </div>
    using System;
    using System.Collections.Generic;
    using System.Text;
    
    namespace GOMLIB.Models
    {
        public partial class Registration
        {        
            public int Registrationid { get; set; }
            public string Email { get; set; }
            public DateTime Createddate { get; set; }
        }
    }

    Thanks,

    Shabbir

    The input elements are missing the name attribute.   The browser does not submit inputs without a name. 

    Monday, May 4, 2020 11:00 AM
  • User-1256377279 posted

    Ok thanks it worked, How to maintain the position of the page after you submit the form, as the form is in the bottom of the page after i submit it goes to the Top i want to stay at form only.

    Monday, May 4, 2020 1:01 PM
  • User475983607 posted

    Ok thanks it worked, How to maintain the position of the page after you submit the form, as the form is in the bottom of the page after i submit it goes to the Top i want to stay at form only.

    This is a new problem!  It is up to you to design and write code. 

    A standard HTML bookmark will work.  Append the bookmark to the HTML form action URL and modify the HTML to include the bookmark. 

    https://www.w3schools.com/html/html_links_bookmarks.asp

    Another option is writing JavaScript to scroll the page location.  Again, this requires modifying the HTML a bit.

    Monday, May 4, 2020 1:16 PM