VS Debugging problem in a cshtml view from a contrib module

Topics: Customizing Orchard, Troubleshooting, Writing modules
Dec 12, 2012 at 4:20 PM
Edited Dec 12, 2012 at 4:22 PM

Writing my first Orchard module, named Contrib.DecoratorField.

I can't set a break point in this .cshtml file when the debugger of VS2012 runs.

I get a comment saying that no symbols have been loaded.
I checked with the Modules window and it states that symbols have been loaded for my module.

Seems that VS believe that this cshtml is not part of my module.
How to change this.

I have rebuilt the orchard solution, reloaded VS, cleared IE cache, without any result.

Moreover I get an exception with this code, its says that @wtag is not allowed, expecting {} ????

 

@model Contrib.DecoratorField.ViewModels.DecoratorFieldViewModel
using Contrib.DecoratorField.Settings;

@{var wtag = "<" + Model.HtmlTag.ToString();}
@switch (Model.HtmlTag){
    case HtmlTagDisplay.div:
    case HtmlTagDisplay.span:
    if ( !string.IsNullOrEmpty(Model.Parameters) )
        wtag = wtag + " " + Model.Parameters;
    if (!string.IsNullOrEmpty(Model.CssClass))
        wtag = wtag + " " + Model.CssClass;
    wtag = wtag + "></" + Model.HtmlTag.ToString() + ">";
    break;
    case HtmlTagDisplay.br:
    wtag = wtag + "/>";
    break;
}
@wtag

Developer
Dec 12, 2012 at 6:05 PM

Initially breakpoints in chtml files can tell you this but after a page refresh (and even more after a recompile) it should properly work. Is the cshtml file's build action set to Content BTW (not None)?

Dec 12, 2012 at 8:29 PM

In fact I found that my code was the problem....too many mistakes.

1) Missing @ before using.

2 This one surprised me, but I had to a lot of braces, each if requesting a {} , event inside an inner @{} ????

@{ 
    string wtag = "<" + Model.HtmlTag.ToString();
    switch (Model.HtmlTag)
    {
        case HtmlTagDisplay.div:
        case HtmlTagDisplay.span:
            {
                if (!string.IsNullOrEmpty(Model.Parameters))
                {
                    wtag = wtag + " " + Model.Parameters;
                }
                if (!string.IsNullOrEmpty(Model.CssClass))
                {
                    wtag = wtag + " " + Model.CssClass;
                }
                wtag = wtag + "></" + Model.HtmlTag.ToString() + ">";
            }
            break;
        case HtmlTagDisplay.br:
            wtag = wtag + "/>";
            break;
    }

}
@wtag

As soon as my code was accepted by compiler, I get the break points working....
My next problem is that @wtag is automatically htmlencoded, which I do not want.....
Developer
Dec 12, 2012 at 8:39 PM

Use Html.Raw().

Dec 12, 2012 at 8:51 PM

Thanks