c# – ASP.NET:错误 – ‘/’应用程序中的服务器错误
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了c# – ASP.NET:错误 – ‘/’应用程序中的服务器错误,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2556字,纯文字阅读大概需要4分钟。
内容图文
我正在研究ASP.NET MVC项目,每次我试图运行我的视图Register.cshtml我都会收到此错误:
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但仍然得到相同的错误..我认为我的错误与位置只!只是简单描述注册理念:我有两类用户填写注册表格,并根据他们选择的内容(在单选按钮中),表格的其余部分将出现在同一页面,让他们继续注册然后将其添加到正确的数据库中.
解决方法:
您还需要向UserController添加HttpGet Register方法:
[HttpGet]
public ActionResult Register()
{
return View();
}
请记住,您需要2种注册方法:
> GET – 从资源请求数据 – 在这种情况下请求转到Register视图.
> POST – 提交数据 – 在这种情况下,将用户信息发送到服务器,以注册用户.
More reading on Http Get and Post
内容总结
以上是互联网集市为您收集整理的c# – ASP.NET:错误 – ‘/’应用程序中的服务器错误全部内容,希望文章能够帮你解决c# – ASP.NET:错误 – ‘/’应用程序中的服务器错误所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。