を生成MVC 3かみそりビューエンジンは、私は...(試す)短いこの質問を維持しようとするコード
私は、Global.asaxのに続いて、この
public class MyViewEngine:RazorViewEngine
{
public MyViewEngine(array viewPathCollection)
{
//My views are all embedded resources and here I
//set ViewLocationFormats and PartialViewLocationFormats
//so that MyVirtualPathProvider can find them inside the assembly
}
protected override bool FileExists(ControllerContext controllerContext, string virtualPath)
{
//Some Logic to check for file
}
}
ようRazorViewEngineを拡張私は私がブラウザでこのコンパイルエラーが発生します(代わりに、すべてのフック)を実行する際のApplication_Startは今、この
ViewEngines.Engines.Clear();
ViewEngines.Engines.Add(new AssemblyResourceViewEngine(ViewPathCollection.ToArray()));
をした
コンパイルエラー 説明:この要求を処理するために必要なリソースのコンパイル中にエラーが発生しました。以下の特定のエラーの詳細を確認し、ソースコードを適切に変更してください。
コンパイラエラーメッセージ:CS0103:名前「モデルは、」現在のコンテキスト内に存在しない
ソースエラー:
public override void Execute() {
Write(model);
WriteLiteral(" MyModelClass \r\n\r\n");
、私はこの
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.225
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace ASP {
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Helpers;
using System.Web.Security;
using System.Web.UI;
using System.Web.WebPages;
using System.Web.WebPages.Html;
using Automotive.Web.Core.Utilities;
public class _Page_bin_MyProject_DLL_Views_Home_Index_cshtml : System.Web.WebPages.WebPage {
#line hidden
public _Page_bin_MyProject_DLL_Views_Home_Index_cshtml() {
}
protected ASP.global_asax ApplicationInstance {
get {
return ((ASP.global_asax)(Context.ApplicationInstance));
}
}
public override void Execute() {
Write(model);
WriteLiteral(" MyModelClass \r\n\r\n");
WriteLiteral("Hello, this is the only thing in the view");
}
}
}
を参照してくださいショーの完全なコンパイルのソースをクリックして上
追加情報:
私はe VirtualPathProviderを使用して、異なるアセンブリ内のビューを検索します。あなたはこの質問に明確化が必要な場合は 私はMyVirtualPathProvider
HostingEnvironment.RegisterVirtualPathProvider(new MyVirtualPathProvider());
を登録するのApplication_Startでこれを行うことは、私に知らせてください。 何か助けていただければ幸いです。
をconfigSectionsで、次のコードを追加します。 'model'はSystem.Web.WebPages.WebPage'の' Model'の有効なプロパティではありません。 – Buildstarted
解決済み..... webconfigファイルをviewsフォルダからbinフォルダにコピーしていますが、解決策が本当に好きではありません...構造を再考する必要があるかもしれません... – labroo
恐ろしいです。あなたのソリューションを回答として投稿し、それを受け入れて、他の人が同様の質問をしている場合に回答を見つけます。 – Buildstarted