开发者

ASP.NET MVC 3 - Portable Area View doesn't find my model

I've started using MvcContrib's Portable Areas and everything works fine for the very simple views, but when I want to use a custom model in my view i get the error saying the namespace doesn't exist.

The view is set to be embedded as resource. And intellisense in the view recognizes the model just fine.

Does anybody have any idea what might cause the problem?

UPDATE

I think it might have to do with the fact that i'm using MEF to load the plugins. I had a similar problem when loading the controllers. I had to build a custom ControllerFactory that would look in the MEF Controllers list if no suitable controller was found by the default controllerfactory.

UPDATE 2

I managed to get rid of the error by providing the RazorBuildProvider with my MEF-loaded assemblies. However, now the view is not found anymore. If the view is not strongly typed it IS found.

    RazorBuildProvider.CodeGenerationStarted += (object sender, EventArgs e) =>
    {
        RazorBuildProvider provider = (RazorBuildProvider)sender;
        foreach (var module in ExternalComponents)
        {
            provider.AssemblyBuilder.AddAssemblyReference(module.GetType().Assembly);
        }
    };

Source Code

The Model

namespace Isis.Plugins.TextArea.TextArea.Models
{
    public class TextAreaModel
    {
        [Required(ErrorMessage = "Field is required")]
        publi开发者_运维问答c string Message { get; set; }
    }
}

The Controller:

namespace Isis.Plugins.TextArea.TextArea.Controllers
{
    [Export(typeof(IController))]
    public class IndexController : Controller
    {
        [HttpGet]
        public ActionResult Index()
        {
            return View(new TextAreaModel() { Message = "Hallow!" });
        }

        [HttpGet]
        public ActionResult Editor()
        {
            return View(new TextAreaModel() { Message = "EDITOR CONTENT" });
        }
    }
}

The View

@model Isis.Plugins.TextArea.TextArea.Models.TextAreaModel

@Model.Message

The error:

Compilation Error

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. 

Compiler Error Message: CS0234: The type or namespace name 'Plugins' does not exist in the namespace 'Isis' (are you missing an assembly reference?)

Source Error:


Line 27:     
Line 28:     
Line 29:     public class _Page_Areas_TextArea_Views_Index_Index_cshtml : System.Web.Mvc.WebViewPage<Isis.Plugins.TextArea.TextArea.Models.TextAreaModel> {
Line 30:         
Line 31: #line hidden


I'm facing similar issue with MEF & razor view engine (trying similar approach you have described). When i load my strongly typed razor views, i get "are you missing an assembly/reference" error.

I tried deploying my assemblies under Bin but that didnt help either.

Only way to avoid it is to do a loadFrom assembly on RazorBuildProvider.

I couldn't find any documentation on RazorBuildProvider other than "not intended to be used directly from your code"

You're code snippet is quite interesting... can you please explain how it works? Where is this expected to be registered - at AppStart?

    RazorBuildProvider.CodeGenerationStarted += (object sender, EventArgs e) =>
{
    RazorBuildProvider provider = (RazorBuildProvider)sender;
    foreach (var module in ExternalComponents)
    {
        provider.AssemblyBuilder.AddAssemblyReference(module.GetType().Assembly);
    }
};

Any clarity would be much appreciated...


I eventually decided to place all the plugins in the Bin directory instead of a custom Plugins directory. It's not the solution I was aiming for, but it works for now.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜