MVC 404错误-仍然是新的
本文关键字:仍然是 错误 MVC | 更新日期: 2023-09-27 17:53:55
所以,我得到一个404错误对我当前的MVC项目提交。我是MVC新手,所以我可能会做一些非常愚蠢的事情。以下是相关代码…
<%@ Page Title="Pies" Language="C#" Inherits="System.Web.Mvc.ViewPage" MasterPageFile="~/site.master" %>
<asp:Content ContentPlaceHolderID="MainContent" runat="server">
<h1>Oh Boy Pies</h1>
<p>Tell us about the pies!</p>
<form action="Process" method="post">
<div class="inputdiv">
<span class="spaced">Name:</span>
<%= Html.TextBox("name") %>
<%= Html.ValidationMessage("name", "*") %>
</div>
</form>
相关处理程序是…
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Ajax;
namespace tabdemo.Controllers
{
public class HomeController : Controller
{
public ActionResult Index ()
{
ViewData ["Message"] = "Demo!";
return View ();
}
public ActionResult Process (FormCollection form)
{
Response.Write (form ["name"]);
Response.End ();
return Redirect ("Index.aspx");
}
}
}
另外,能否解释一下如何使用TextBoxFor实现?我看过一些例子,但我一点也不明白。
编辑:这是主页
<%@ Master Language="C#" Inherits="System.Web.Mvc.ViewMasterPage" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<asp:ContentPlaceHolder ID="MainContent" runat="server">
</asp:ContentPlaceHolder>
</body>
</html>
应该是return RedirectToAction("Index")
。MVC不使用PAGES,而是依赖于Controller
来路由请求。
控制器返回视图,或者重定向到另一个渲染视图的控制器。
编辑是的,动作方法是不正确的(刚才看到)
<form action="/Home/Process" method="post">
<div class="inputdiv">
<span class="spaced">Name:</span>
<%= Html.TextBox("name") %>
<%= Html.ValidationMessage("name", "*") %>
</div>
</form>