我正在ASP.NET MVC中开发一个登录页面,并且遇到了一个问题:

Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable.  Please review the following URL and make sure that it is spelled correctly.


要求的网址:/验证

我厌倦了一条自定义路线,但似乎无法解决。
 这是我这里唯一的控制器

 public class HomeController : Controller
{
    // GET: Home

    MySqlConnection conn = new MySqlConnection();
    MySqlCommand cmd = new MySqlCommand();
    MySqlDataReader dr;

    [HttpGet]
    public ActionResult Index()
    {
        return View();
    }
    void connectionString()
    {
        conn.ConnectionString = "Server=localhost;Database=prodavnica;Uid=root`;Pwd=1234;Port=3306";
    }
    [HttpPost]
    public ActionResult Verify(Account acc)
    {


            connectionString();
            conn.Open();
            cmd.Connection = conn;
            cmd.CommandText = "select * from prodavnica.vraboteni where korisnik='" + acc.Username + "'and lozinka='" + acc.Password + "' ";

            if(dr.Read())
            {
                conn.Close();
                return View("Success");
            }
            else
            {
                conn.Close();
                return View();

            }

    }
}


}
路由配置:

     routes.MapRoute(

            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
        );


这是项目的前端,我也有一个布局,我尝试了多次,但仍然遇到相同的错误

/head>
<body>
<div class="login-form">
    <form action="Verify" method="post">
        <h2>Најави се</h2>
        <div class="form-group">
            <label>Корисник : </label>
            <input type="text" name="Username" class="form-control" required="required" />
        </div>
        <div class="form-group">
            <label>Лозинка: </label>
            <input type="password" name="Password" class="form-control" required="required" />
        </div>
        <div class="form-group clearfix">
            <button type="submit" class="btn btn-primary pull-left">
                Најави се
            </button>
            <label class="checkbox-inline pull-left remember-me"><input type="checkbox" /> Запамти ме</label>
        </div>
        <div><a href="#">Проблеми со најавувањето ? </a></div>
    </form>
</div>


它具有发布方法。

最佳答案

我认为您需要在该表单操作上执行/ Verify或/ Home / Verify,但缺少该斜杠。

如果这不起作用,请使用chrome并在“网络”标签上打开开发人员工具,以确保这是发布请求,并确保参数正确传递给操作。如果您需要帮助,请在此处发布您的看法。

关于c# - 如何在ASP.NET MVC中修复404'找不到资源',我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/58227752/

10-13 07:56