我工作的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,但仍然得到相同的錯誤..我認爲我的錯誤只與位置!只是對註冊理念的簡單描述:我有兩種類型的用戶填寫註冊表單,並根據他們選擇的內容(單選按鈕),表單的其餘部分將出現在同一頁面中,以便讓他們繼續註冊將其添加到正確的數據庫。
你有什麼定義的路線? – Richard
我已經將控制器=「Home」,action =「Index」的RegisterRoutes更改爲controller =「User」,action =「Register」 – user5067119