1

Who can help me, i have a create button on my View layout for login, it has this fields username and password, login button(this validates if the user exist) and create(this i am struggling to link it).

I have this on my AppStart, RouteConfig.cs logic below; The question must i need to create that logic on this file(Create page functionality on RouteConfig.cs)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

namespace eNtsaPortalWebsiteProject
{
    public class RouteConfig
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Account", action = "Login", id = UrlParameter.Optional }
            );
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

namespace eNtsaPortalWebsiteProject
{
    public class RouteConfig
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Account", action = "Create", id = UrlParameter.Optional }
            );
        }
    }
}

Views/Account/Create.cshtml page something that will link this route to handle load from the web? I don't know please assist me, as i still new to MVC web development.

Logic for login on Views/Account/login.cshtml:

@model eNtsaPortalWebsiteProject.Models.Login

@{
    ViewBag.Title = "Login";
}

@{
        Layout = "~/Views/Shared/_LoginLayout.cshtml";
}

<script src="~/Scripts/jquery-1.9.1.js"></script>
<script src="~/bootstrap/js/bootstrap.min.js"></script>
<script src="~/Scripts/jquery.min.js"></script>
<link href="~/bootstrap/css/bootstrap.min.css" rel="stylesheet" />

<div data-="mainContent">
    <section class="container">
        <div class="logo col-sm-12 text-center col-md-12"> <img alt="" src="~/Images/eNtsa.png" /></div>
        <div class="clearfix"></div>

        <div class="container">
            <div class="row">
                <div id="MyWizard" class="formArea LRmargin">
                    @using (Html.BeginForm())
                    {
                        @Html.AntiForgeryToken()

                        <div id="divMessage" class="text-center col-md-12 col-md-offset-12 alert-success">
                            @Html.ValidationSummary()
                        </div>
                        <div class="glyphicon-log-out col-sm-12 text-center col-md-12"> <img alt="" src="~/Images/gcobani.jpg" /></div>
                        <div class="clearfix"></div>
                        <div class="col-md-12 col-md-offset-10 col-xs-12">
                            <div class="loginPage panel-info">
                                <span class=""><i class="glyphicon glyphicon-user">Username</i></span>
                                <div class="form-group text-center">
                                    @Html.TextBoxFor(model => model.username, new { @class = "form-control text-center", autocomplete = "off" })
                                    @Html.ValidationMessageFor(model => model.username)
                                </div>

                                <div class="form-group">
                                    <span class=""><i class="glyphicon glyphicon-user">Password</i></span>
                                    @Html.PasswordFor(model => model.password, new { @class = "form-control text-center", autocomplete = "off" })
                                    @Html.ValidationMessageFor(model => model.password)
                                </div>
                            </div>

                            <div class="form-group">
                                <input id="BtnLogin" type="submit" class="btn btn-success btn-pressure" name="BtnLogin" value="Login" />
                                <input id="BtnReset" type="reset" value="Create" class="btn btn-info btn-pressure" name="BtnReset" value="Reset" />
                            </div>
                        </div>
                    }
                    <div class="clear"></div>
                </div>
          </div>
ArunPratap
  • 4,816
  • 7
  • 25
  • 43
  • 1
    what is issue can you explain briefly? – Azhar Jan 23 '20 at 08:25
  • My create button is not functional, that is why i am asking above is my approach to that is correct way. Meaning when i click the create from login.cshmtl with then form must send me or allow me to create a new user. I have also create some method on my Controller class – eNtsa2019 Mkontwana Jan 23 '20 at 08:39

1 Answers1

0

Your button type for "Create" is set to "reset":

<div class="form-group">
   <input id="BtnLogin" type="submit" class="btn btn-success btn-pressure" name="BtnLogin" value="Login" />
   <input id="BtnReset" type="reset" value="Create" class="btn btn-info btn-pressure" name="BtnReset" value="Reset" />
</div>

As per W3Schools, this will reset the form to its initial values: https://www.w3schools.com/tags/att_button_type.asp

  • button: The button is a clickable button
  • submit: The button is a submit button (submits form-data)
  • reset: The button is a reset button (resets the form-data to its initial values)

Example: https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_button_type

If you want the "Create" button to send back the form to your controller, I suggest you try changing the button type to "Submit"

James S
  • 171
  • 1
  • 6
  • the home screen should have a login button and create button. login for an existing users return to home page, hope make sense what i am trying to accomplish here. Last question if i am chaning that value on my form. Must i call this page from my RouteConfig.cs? – eNtsa2019 Mkontwana Jan 23 '20 at 11:00
  • I don't think you will need to make any changes to your RouteConfig.cs for this. If you update the "Create" button so that the type is "submit" then both buttons will submit the form. After that you can handle whatever further logic is required in the controller. There are a lot of different ways you can proceed from there to achieve what you're trying to do. – James S Jan 23 '20 at 11:10
  • Here is a link to another question which gives a simple explanation on how to manage having multiple submit buttons to the same form: https://stackoverflow.com/questions/20616154/how-to-handle-two-submit-buttons-on-mvc-view – James S Jan 23 '20 at 11:14
  • 1
    Thanks@James, i think have an idea based on what you sent to me as link. Busy now making those implementation on my MVC. – eNtsa2019 Mkontwana Jan 23 '20 at 13:17