FNCSoftware / SharedWebComponentsMef

A prototype that demonstrates what a plugin-based architecture using MEF looks like.
13 stars 5 forks source link

Strongly-typed model in client views? #3

Open drmcclelland opened 9 years ago

drmcclelland commented 9 years ago

I tried modifying Index.cshtml in the Client1.Page project to use a strongly-typed mode, but I get an error. If you have any ideas of how to implement this, I'd appreciate it.

First off, here are the modifications I made:

Model:

namespace Client1.Page.Models
{
    public class Model
    {
        public string Message { get; set; }
    }
}

View:

@model Client1.Page.Models.Model

<span>Client 1 Message = @Model.Message</span>

Controller action:

public ActionResult Index()
{
    var model = new Client1.Page.Models.Model() { Message = "A very excited message!" };
    return View(model);
}

Here is the error I receive:

Server Error in '/' Application.

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: CS0103: The name 'model' does not exist in the current context

Source Error:

Line 42: BeginContext("~/Plugins/Client1.Page/Views/Test/Index.cshtml", 150, 5, false); Line 43: Line 44: Write(model); Line 45: Line 46: EndContext("~/Plugins/Client1.Page/Views/Test/Index.cshtml", 150, 5, false);

Source File: c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\f947cd85\71552e5a\App_Web_index.cshtml.dd1163fa.itk9ur2d.0.cs Line: 44

jhcodeh commented 9 years ago

Same probleme here. My first try to handle missing usings in the razor views are:

public RazorNamespaceRegister(IEnumerable assemblies) { foreach (Assembly assembly in assemblies) { List nameSpaces = assembly.GetTypes().Select(t => t.Namespace).Distinct().ToList(); foreach (string nameSpace in nameSpaces) { . WebCodeRazorHost.AddGlobalImport(nameSpace); } } }

It is a class I called from the MefConfig.cs like this: new RazorNamespaceRegister(assemblies); But still don't work because the usings or assembly reference still not found.

Possibly, a small step in the right direction.

so long.