1

I am working on a project, I have 2 controllers: AccountController, Table_1Controller. On the Account controller, I returned a view with the path to the other controller's view. When I run the view of AccountController it returns the Table_1Controller but the URL is https://localhost:44365/Account/Verify. I don't get why it cant return https://localhost:44365/Table_1/Create. Can someone help me fix this?

AccountController.cs :

namespace LoginApp.Controllers
{
    public class AccountController : Controller
    {
        private const string OtherController = "~/Views/Table_1/Create.cshtml";
        SqlConnection con = new SqlConnection();
        SqlCommand com = new SqlCommand();
        SqlDataReader dr;
        // GET: Account
        [HttpGet]
        public ActionResult Login()
        {

            return View();
        }
        void connectionString()
        {
            con.ConnectionString = "private;";
        }
        [HttpPost]
        public ActionResult Verify(Account acc)
        {
            connectionString();
            con.Open();
            com.Connection = con;
            string v = @"SELECT * FROM Table_Login WHERE Username = '" + acc.Name + "' and Password ='" + acc.Password + "'";
            com.CommandText = v;
            dr = com.ExecuteReader();
            if(dr.Read())
            {
                con.Close();
                return View(OtherController);
            }
            else
            {
                con.Close();
                return View("Error");
            }
    }

Table_1Controller:

1
  • 1
    I believe you are merely returning the specified view within the /Account/Verify url. You might want to return redirect instead. Commented Jul 26, 2021 at 21:36

1 Answer 1

1

you can use relative route :

return View("../Table_1/Create");

inside code

if(dr.Read())
{
    con.Close();
    return View("../Table_1/Create");
}

or use

return RedirectToAction("Create","Table_1");

inside code

if(dr.Read())
{
    con.Close();
    return RedirectToAction("Create","Table_1");
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.