skip to Main Content

This form instead using the "Verify function in my controllers goes to the subpage /Account/Verify
Form:

@using (Html.BeginForm("Verify", "Account", FormMethod.Post))
{
    <span>Enter Your Email:</span>@Html.TextBoxFor(m=>m.Name)<br />
    <span>Enter Your Password:</span>@Html.TextBoxFor(m=>m.Password)<br />
    <input id="Submit" type="submit" value="submit" />
}

Method:

[HttpPost] public ActionResult Verify(Account acc)
{
    connectionString();
    con.Open();
    com.Connection = con;
    com.CommandText = "select * from Users where Name = '"+acc.Name+"' and password = '"+acc.Password+"'";
    dr = com.ExecuteReader();
    if (dr.Read())
    {
        con.Close();
        return View("Home");
    }
    else {
        con.Close();
        return View("Privacy");     
    }
}

EDIT: Adding picture so the Controller and it’s location are visible

enter image description here

I feel like I tried everything rn and I’m out of ideas how could I do this

I wanted the form proceed and to be redirected to one of the subpages I’ve Pointed

2

Answers


  1. Chosen as BEST ANSWER

    it finally worked, this is how it should be:

    Html.BeginForm("Verify", "Account", FormMethod.Post

    So basically first goes method name and second in controller name, but I'm sure I've tried this couple of times, but it didn't work previously. Anyway the problem seems solved for now


  2. Please try to mark your HttpMethod in controller.
    Like:

    [HttpPost("Verify")] 
    public ActionResult Verify(Account acc)
    

    Also in the browser please open developer tools windows (F12 or Right click and inspect will enough for it.) after then go to network tab. You can see the network requests on there. Just keep monitoring the network packages and press the form submit button then verify is your endpoint correct or not.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search