单击链接

时间:2017-07-26 08:53:44

标签: html asp.net-mvc

我有这个HTML页面。当我点击html页面上的链接<a href="~/FloorPlan/UserLabFloor">时,它会抛出错误“无法找到资源”我无法解决问题。

这是html代码(Index.cshtml)

    <nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
        <div class="container">
            <!-- Brand and toggle get grouped for better mobile display -->
            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1"></button>
            </div>
            <!-- Collect the nav links, forms, and other content for toggling -->
            <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">

            </div>
            <!-- /.navbar-collapse -->
        </div>
        <!-- /.container -->
    </nav>
    <div class="container">
        <div class="row">
            <div class="col-lg-12">
                <h1 class="page-header">Dashboard</h1>
            </div>
            <!-- /.col-lg-12 -->
        </div>
        <!-- /.row -->
        <div class="row">
            <div class="col-lg-3 col-md-6">
                <div class="panel panel-red">
                    <div class="panel-heading">
                        <div class="row">
                            <div class="col-xs-3">
                                <i class="fa fa-ticket fa-5x"></i>
                            </div>
                            <div class="col-xs-9 text-right">
                                <div class="huge"><i class="fa fa-cog fa-spin"></i></div>
                                <div>Budget</div>
                            </div>
                        </div>
                    </div>
                    <a href="~/FloorPlan/UserLabFloor">
                        <div class="panel-footer">
                            <span class="pull-left">View Details</span>
                            <span class="pull-right"><i class="fa fa-arrow-circle-right"></i></span>
                            <div class="clearfix"></div>
                        </div>
                    </a>
                </div>
            </div>

    </div>

    <script src="Scripts/jquery-1.10.2.js"></script>

    <script src="Scripts/bootstrap.min.js"></script>

UserLabFloor.cshtml:

@model  USTGlobal.WorkBench.UI.Models.FloorPlanViewModel 
@{
    ViewBag.Title = "RequestForm";

}

    <div class="row">
        <div class="col-lg-8">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h2 class="page-header">Request Form</h2>
                </div>
            </div>
            @using (Html.BeginForm("UserLabFloor", "FloorPlan"))
            {
                <div class="row">
                    <div class="col-lg-8">
                        <div class="form-horizontal">
                            <div class="form-group">
                                <label class="control-label col-lg-4">Period:</label>
                                <div class="col-lg-8">
                                    @Html.DropDownList("Quarter", new SelectListItem[] { (new SelectListItem() { Text = "Q1", Value = "1" }), (new SelectListItem() { Text = "Q2", Value = "2" }), (new SelectListItem() { Text = "Q3", Value = "3" }), (new SelectListItem() { Text = "Q4", Value = "4" }) }, "-- Select Quarter --", new { @class = "form-control" })
                                    <br />
                                    @Html.DropDownList("Year", new SelectListItem[] { (new SelectListItem() { Text = "2016", Value = "2016" }), (new SelectListItem() { Text = "2017", Value = "2017" }) }, "-- Select Year --", new { @class = "form-control" })
                                </div>
                            </div>
                        </div>
                        <div class="form-horizontal">
                            <div class="form-group">
                                <label class="control-label col-lg-4">Line ID:</label>
                                <div class="col-lg-8">
                                    @Html.TextBoxFor(model => model.floorConfig.LineID, new { onkeypress = "return isNumberKey(event)", @class = "form-control" })
                                </div>
                            </div>
                        </div>

                        <div class="form-horizontal">
                            <div class="form-group">
                                <label class="control-label col-lg-4">Project:</label>
                                <div class="col-lg-8">
                                    @Html.TextBoxFor(model => model.floorConfig.Project, new { onkeypress = "return isNumberKey(event)", @class = "form-control" })
                                </div>
                            </div>
                        </div>


                        <div class="form-horizontal">
                            <div class="form-group">
                                <label class="control-label col-lg-4">Budget:</label>
                                <div class="col-lg-8">
                                    @Html.TextBoxFor(model => model.floorConfig.Budget, new { onkeypress = "return isNumberKey(event)", @class = "form-control" })
                                </div>
                            </div>
                        </div>


                    </div>
                </div>

                <div class="row">
                    <div class="col-lg-offset-4" style="padding: 10px 0px 0px 0px;">
                        <input type="submit" id="btnSubmit" value="Submit" class="btn btn-lg btn-success" />
                        <input type="button" id="btnCancel" value="Clear" class="btn btn-lg btn-success" />
                    </div>
                </div>

            }
        </div>
    </div>

FloorPlanController.cs

[ActionName("UserLabFloor")]
        [HttpPost]
        public ActionResult UserLabFloor()
        {
            FloorConfirguration floorConfig = new FloorConfirguration();

            floorService.SaveLabFloorConfig(floorConfig);

            return View("UserLabFloor");

        }

1 个答案:

答案 0 :(得分:0)

正如@Nirman提到你在FloorPlanController.cs中错过了一个GET处理程序。

您在表单提交(POST)后返回UserLabFloor视图,但您没有[HttpGet]方法的UserLabFloor()定义。

这意味着浏览器将在POST后发出GET请求,但在这种情况下MVC RouteTable中没有匹配的路由(404)。

要了解有关此行为的更多信息,请阅读https://en.wikipedia.org/wiki/Post/Redirect/Get