vs 2010 から vs2012 に mvc 3 アプリを移植しました。
移植されたアプリは .NET 4 を使用しています。
古いビットはすべて機能しますが、vs 2012 で作成された新しいビューでは、ビュー エンジンはビューの .cshtml ファイルを探しません。
たとえば、ユーザーが Solicitors 領域の Welcome コントローラーで index アクションを要求すると、URL は次のようになります。
mysite.com/solicitors/welcome/gg
(gg はユーザー名です)。その場合、返されるエラーは次のとおりです。
ビュー「インデックス」またはそのマスターが見つからないか、検索された場所をサポートするビュー エンジンがありません。次の場所が検索されました: ~/Areas/Solicitors/Views/Welcome/Index.aspx ~/Areas/Solicitors/Views/Welcome/Index.ascx ~/Areas/Solicitors/Views/Shared/Index.aspx ~/Areas/Solicitors /Views/Shared/Index.ascx ~/Views/Welcome/Index.aspx ~/Views/Welcome/Index.ascx ~/Views/Shared/Index.aspx ~/Views/Shared/Index.ascx ~/Areas/Solicitors/ Views/Welcome/gg.master ~/Areas/Solicitors/Views/Shared/gg.master ~/Views/Welcome/gg.master ~/Views/Shared/gg.master ~/Areas/Solicitors/Views/Welcome/gg. cshtml ~/Areas/Solicitors/Views/Welcome/gg.vbhtml ~/Areas/Solicitors/Views/Shared/gg.cshtml ~/Areas/Solicitors/Views/Shared/gg.vbhtml ~/Views/Welcome/gg.cshtml ~ /Views/Welcome/gg.vbhtml ~/Views/Shared/gg.cshtml ~/Views/Shared/gg.vbhtml
web.config の appsettings に次のキーを既に追加しましたが、違いはありません。
<add key="webpages:Version" value="1.0" />
編集:
SolictorAreaRegistration.cs でルーティングします。
context.MapRoute(
"Solicitors_Welcome",
"Solicitors/Welcome/{nameUser}",
new { controller = "Welcome", action = "Index", nameUser = UrlParameter.Optional }
);
編集2:
RouteDebug を使用すると、正しいコントローラーとアクションが見つかっていることがわかります。
ルートデータ
キー値
ユーザー名: gg
コントローラー: ようこそ
アクション: インデックス
データトークン
キー値
名前空間: System.String[]
分野: 事務弁護士
UseNamespaceFallback: False
編集3:
デバッグからわかるように、ルートは正しく見つかりました: Index アクションがヒットしました。
ビューを呼び出す行が呼び出されると、問題が発生します。
namespace MyApp.Areas.Solicitors.Controllers
{
[Authorize]
public partial class WelcomeController : Controller
{
//
// GET: /Solicitors/Welcome/
public virtual ActionResult Index(string nameUser)
{
return View("Index", nameUser);
}
}
}