0
MVCフレームワークのRTW 1.0をインストールしました。私は過去にRC2を使ってチュートリアルを行っていました。私は今RC2で持っていなかった基本的なルーティングがうまくいかない問題があります。ASP .NET MVCのデフォルトルーティングの問題RTW 1.0
VS 2008で新しいMVCアプリケーションを作成した場合、ホームページのルーティングはそのままでは機能しません。
仕事や404エラーを与えていない、次ただし、何らかの理由
http://mydomain/
http://mydomain/Home/Index/1
ため、次のURLの仕事。
http://mydomain/Home
http://mydomain/Home/Index
マイRegisterRoutes方法がデフォルトであり、この
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = "" } // Parameter defaults
);
}
マイHomeController.csこの
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace MyNamespace.Controllers
{
[HandleError]
public class HomeController : Controller
{
public ActionResult Index()
{
ViewData["Message"] = "Welcome to ASP.NET MVC!";
return View();
}
public ActionResult About()
{
return View();
}
}
}
のように見えるとインデックスビューが生成されるだけで、デフォルトで
のように見えます<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>
<asp:Content ID="indexTitle" ContentPlaceHolderID="TitleContent" runat="server">
Home Page
</asp:Content>
<asp:Content ID="indexContent" ContentPlaceHolderID="MainContent" runat="server">
<h2><%= Html.Encode(ViewData["Message"]) %></h2>
<p>
To learn more about ASP.NET MVC visit <a href="http://asp.net/mvc" title="ASP.NET MVC Website">http://asp.net/mvc</a>.
</p>
</asp:Content>