2017-07-26 60 views
0

我有這個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"); 

     } 
+2

使用'HREF = 「@ Url.Action(」 UserLabFloor 「 」平面圖「)」'來生成正確的URL。 –

+0

這不適合我。 – beginner

+2

然後,您在FloorPlanController中沒有名爲UserLabFloor()的公共方法 –

回答

0

正如@Nirman提到你在FloorPlanController.cs中缺少GET處理程序。

您在表單提交(POST)後返回UserLabFloor視圖,但您沒有爲UserLabFloor()方法定義[HttpGet]定義。

這意味着瀏覽器將在POST後發出GET請求,但在這種情況下,MVC RouteTable中沒有匹配的路由(404)。

要了解更多關於此行爲,請閱讀https://en.wikipedia.org/wiki/Post/Redirect/Get