How "Style.Include" works?

Nov 3, 2010 at 7:54 PM

I am looking at the following file "src\Orchard.Web\Themes\TheThemeMachine\Views\Layout.cshtml" and here is the following declarations inside:

Style.Include("http://fonts.googleapis.com/css?family=Lobster&subset=latin");
Style.Include("site.css");

When I am trying to do the same in my partial view in custom module it builds ok, but when running from Orchard I am getting compilation error:

"Compiler Error Message: CS0103: The name 'Style' does not exist in the current context"

So my question is how it works in Orchard and how make it work in my module. Thanks!

Coordinator
Nov 3, 2010 at 9:15 PM

Instead of using a partial view, you could try to create a shape. From your current view, do

var foo = New.Foo();
foo.Bar = "Hello World";
Display(foo);

Create a file in your theme or your module, under /Views, named foo.cshtml, with this content:

@Model.Bar

You'll then see "Hello World" in this shape (sort of partial view), and you can use the Style object with it. Also, any theme will be able to override your default template.

Nov 4, 2010 at 9:48 AM

Thanks a lot for your help! And you mean that it is not possible to use Style.Include from my code? If so then why and how it works in Orchards modules?

Coordinator
Nov 4, 2010 at 3:38 PM

I just say it will work from a standard view resulting from a controller, or from any shape.

Nov 17, 2010 at 7:17 PM

I've tried to create this in the way you were suggesting, I have a view called Login.cshtml with the following code:

<span>Login successfull</span>
@{
    var foo = New.Foo();
    foo.Bar = "Hello World";
    Display(foo);
}

And I've created a view called Foo.cshtml with the following content:

@Model.Bar

So when I am running my Login view I am getting following 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: CS0103: The name 'New' does not exist in the current context

Source Error:


Line 1:  <span>Login successfull</span>
Line 2: @{
Line 3: var foo = New.Foo();
Line 4: foo.Bar = "Hello World";
Line 5: Display(foo);

Coordinator
Nov 24, 2010 at 4:27 PM

Can you provide the source for your controller also, I would like to check how you are returning the View.
Thanks

Nov 24, 2010 at 5:07 PM

Controller declared in the following manner:

  [HandleError, Themed]
  public class UserAccountController : Controller

Here is my code for controller's action:

 public ActionResult Index()
        {
            return View();
        }

Here is my Index.cshtml view code:

<span>Login successfull</span>
@{
var foo = New.Foo();
foo.Bar = "Hello World";

Display(foo);
}
Here is my Index.cshtml view code:

@Model.Bar