因此,我在提交当前 MVC 项目时收到 404 错误。我是 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>