2015-07-20 34 views
4

我工作的ASP.NET MVC項目和每一個我試圖運行我的看法Register.cshtml時間服務器錯誤我得到這個錯誤:ASP.NET:錯誤 - 「/」中應用

Server Error in '/' Application. 

The resource cannot be found. 

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. 

Requested URL: /User/Register 

我」米試圖開發一個視圖代碼註冊頁面:

@{ 
     ViewBag.Title = "Register"; 
     Layout = "~/Views/Shared/_Layout.cshtml"; 
    } 

<h2>Register</h2> 

<form action='@Url.Action("Register", "Controller")'> 

    <input type="hidden" name="FormType" value="A" /> 
    <input type="hidden" name="FormType" value="B" /> 
    <input type="text" name="Name" placeholder="enter your name" /> 
    <input type="text" name="Password" placeholder="enter your name" /> 
    <input type="radio" name="typeOfForm" class="radioBtn" value="A">Form A 
    <input type="radio" name="typeOfForm" class="radioBtn" value="B">Form B 
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> 
    <div style="display: none" id="formA" action="/actionA"> 
     <input type="text" name="City" placeholder="City" /> <input type="submit" value="Register Me!" /> 
    </div> 

    <div style="display: none" id="formB" action="/actionB"> 
     <input type="text" name="Age" placeholder="Age" /><input type="submit" value="Register Me!" /> 
    </div></form> 

<script> 
    $('.radioBtn').click(function() { 
     var formType = $(this).val(); 
     //alert(formType); 
     if (formType == "A") { 
      $('#FormA').show(); 
      $('#FormB').hide(); 
     } else { 
      $('#FormB').show(); 
      $('#FormA').hide(); 
     } 
    });</script> 

UserController.cs

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.Mvc; 

namespace BootstrapSite4.Controllers 
{ 
    public class UserController : Controller 
    { [HttpGet] 
     [HttpPost] 
     // GET: User 
     public ActionResult Register(char FormType, string name, string password) 
     { 
      Seller S = new Seller(); 
      DeliveryMan D = new DeliveryMan(); 
      if (FormType=='A') 
       S.Name = name; 
      else 
       D.Name = name; 
      return View();}}} 

我試圖改變我的RegisterRoutes,但仍然得到相同的錯誤..我認爲我的錯誤只與位置!只是對註冊理念的簡單描述:我有兩種類型的用戶填寫註冊表單,並根據他們選擇的內容(單選按鈕),表單的其餘部分將出現在同一頁面中,以便讓他們繼續註冊將其添加到正確的數據庫。

+0

你有什麼定義的路線? – Richard

+0

我已經將控制器=「Home」,action =「Index」的RegisterRoutes更改爲controller =「User」,action =「Register」 – user5067119

回答

4

你需要一個HttpGetRegister方法添加到UserController還有:

[HttpGet] 
public ActionResult Register() 
{ 
    return View(); 
} 

記住,你需要2種註冊方法:

  1. GET - 請求數據從資源 - 在這種情況下,請求轉到註冊視圖
  2. POST - 提交數據 - 在這種情況下向用戶發送信息到服務器,註冊用戶

More reading on Http Get and Post

+0

謝謝,但仍然出現同樣的錯誤! :( – user5067119

+1

@ user5067119,你能更新控制器代碼嗎? –

+0

我已更新.. – user5067119