So, I’m getting a 404 error on my current MVC project on submit. I’m new to MVC, so I’m likely doing something exceptionally stupid. Here’s the relevant code…
<%@ 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>
And the relevant handler is…
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");
}
}
}
Also, can people explain how this would be implemented using TextBoxFor, for example? I’ve seen examples of it, but I don’t understand it at all.
edit: Here’s the masterpage
<%@ 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>
it should be
return RedirectToAction("Index"). MVC does not use PAGES, instead relies onControllerto route the request.Controllers return the View, or Redirect to another Controller, which renders the view.
EDIT
And yes, the action method was incorrect(just saw)