2015-07-20 15 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