0

そのため、送信時に現在の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>
4

1 に答える 1

1

する必要がありますreturn RedirectToAction("Index")ControllerMVCはPAGESを使用せず、代わりにリクエストのルーティングに依存します。

コントローラはビ​​ューを返すか、ビューをレンダリングする別のコントローラにリダイレクトします。

編集 そしてはい、アクションメソッドは正しくありませんでした(ちょうど見ました)

<form action="/Home/Process" method="post">
    <div class="inputdiv">
        <span class="spaced">Name:</span>
        <%= Html.TextBox("name") %>
        <%= Html.ValidationMessage("name", "*") %>
    </div>
</form>
于 2013-01-17T20:01:44.343 に答える