Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Matt Taylor 873 posts 2086 karma points
    Feb 05, 2013 @ 15:30
    Matt Taylor
    0

    Please help me get a basic MVC macro to work in V6

    Hello,

    I'm swotting up on MVC because I want to use it in my next site build.
    I quite new to MVC but have plent of experience with Umbrcao and ASP.Net.

    I've been through the Music Store tutorial to get an idea of how it hangs together as well as looking at some MVC Umbrcao related doces.

    I've waited until V6 because I wanted to start with a version that had complete support for MVC, which I understand it now has.

    There's currently not much in the way of tutorials on how to get an MVC macro working specifically with V6 but I have just watched and implemented the MVC in Umbraco 4 video for my V6 site.

    I'm trying to build and MVC macro that I can drop into a rich text editor but after following the video and making a few allowances for the different versions it is not working.

    I simply get an error when the page is loaded.

    Error loading MacroEngine script (file: ~/Views/MacroPartials/Index.cshtml)

    Some things I have not done because of the versions differences:

    1. I have not set the AntiForgeryToken
    2. I have not used MvcBridge

    The model is very basic:

    public class StatusViewModel
        {
            [Required]
            public string StatusText { get; set; }
        }

    So is the Controller:

    public class StatusController : Controller
        {
            //
            // GET: /Status/

            [HttpGet]
            public PartialViewResult Index()
            {
                return new PartialViewResult();
            }

            [HttpPost]
            public PartialViewResult Index(StatusViewModel model)
            {
                if (ModelState.IsValid)
                {

                }
                return new PartialViewResult();
            }
        }

    The view was auto generated:

    @model MvcUmbracoTest.Models.StatusViewModel

    <script src="~/Scripts/jquery-1.5.1.min.js"></script>
    <script src="~/Scripts/jquery.validate.min.js"></script>
    <script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script>

    @using (Html.BeginForm()) {
        @Html.ValidationSummary(true)

        <fieldset>
            <legend>StatusViewModel</legend>

            <div class="editor-label">
                @Html.LabelFor(model => model.StatusText)
            </div>
            <div class="editor-field">
                @Html.EditorFor(model => model.StatusText)
                @Html.ValidationMessageFor(model => model.StatusText)
            </div>

            <p>
                <input type="submit" value="Create" />
            </p>
        </fieldset>
    }

    What have I not done?

    Thanks, Matt

     

  • Matt Taylor 873 posts 2086 karma points
    Feb 05, 2013 @ 15:37
    Matt Taylor
    0

    The defaultRenderingEngine is set to Mvc.

  • Damian Green 452 posts 1433 karma points
    Feb 05, 2013 @ 16:57
    Damian Green
    0

    Don't you need to call your controller StatusSurfaceController

    The word surface needs to be in there if i remember rightly.


  • Damian Green 452 posts 1433 karma points
    Feb 05, 2013 @ 17:00
    Damian Green
    0

    Also inherit from Umbraco.Web.Mvc.SurfaceController

    Just had a quick look at a test i did a while back and thats how i did it... unless ts all changed!?? Not played with it for a bit.


  • Damian Green 452 posts 1433 karma points
    Feb 05, 2013 @ 17:04
  • Matt Taylor 873 posts 2086 karma points
    Feb 05, 2013 @ 17:16
    Matt Taylor
    0

    Thanks for the help Damien, I remember coming accross SurfaceController documentation here but I wasn't sure if it applied.

    The MVC stuff in the recent releases has all been moving so quick it difficult to know what's applicable in the documentation.

    I've tried calling the controller StatusSurfaceController and inheriting from Umbraco.Web.Mvc.SurfaceController but I still have the same problem at the moment.

    I'm going to start from scratch and follow that tutorial you posted and see where that gets me in V6. :-)
    Will let you know.

    Cheers, Matt

  • Damian Green 452 posts 1433 karma points
    Feb 05, 2013 @ 18:49
    Damian Green
    0

    What do you get in the debug output?

    add the umbDebugShowTrace=true to the request and make sure debug is on - you might get a little more info to go on from that.

    And check your view is inheriting the correct class:

    @inheritsUmbraco.Web.Mvc.UmbracoViewPage<MvcUmbracoTest.Models.StatusViewModel>


  • Damian Green 452 posts 1433 karma points
    Feb 05, 2013 @ 18:51
    Damian Green
    0

    Let me know if you dont get it working and i'll have a bash - need to get a v6 site spun up myself.  

    I did manage to write a custom controller in 4.10 because i wrote an image handler as a test - so i could look that up.

     

     

  • Damian Green 452 posts 1433 karma points
    Feb 05, 2013 @ 18:53
  • Matt Taylor 873 posts 2086 karma points
    Feb 05, 2013 @ 20:11
    Matt Taylor
    0

    Strangely ?umbDebugShowTrace=true is not working.

    umbracoDebugMode is set to true in the web.config. A v6 bug maybe?

  • Matt Taylor 873 posts 2086 karma points
    Feb 05, 2013 @ 20:32
    Matt Taylor
    0

    I followed the "Creating a Login form with Umbraco MVC SurfaceController" tutorial and it all worked fine.

    I then moved the view to the MacroPartials folder so that I could create a macro out of it. That's when it goes wrong:

    Error loading MacroEngine script (file: ~/Views/MacroPartials/MemberLogin.cshtml)

    Interestingly the view continues to work from the template with

    @Html.Action("MemberLogin","MemberLoginSurface")

    even though I have moved it.

  • Damian Green 452 posts 1433 karma points
    Feb 05, 2013 @ 22:29
    Damian Green
    0

    Is the security set ok on the Partials folder?

     

     

  • Damian Green 452 posts 1433 karma points
    Feb 05, 2013 @ 22:45
    Damian Green
    0

    I cant get the trace either. I know logging has been moved into log files but would have thought trace would stay the same so maybe a bug?

  • Damian Green 452 posts 1433 karma points
    Feb 05, 2013 @ 23:01
    Damian Green
    0

    Looks like i was right - trace now lumped into the log files.

     

  • gary 385 posts 916 karma points
    Feb 06, 2013 @ 08:44
    gary
    0

    Hi Matt and Damian

    Don't know if it is related, but had an odd one - 

    @Html.Partial("navigation")
     
    System.Web.Mvc.HtmlHelper etc. . . does not contain a definition for Partial and no extension method Partial.
    This was V6 on a live server, but showed no error on local machine.
    Matt, on a diferent tip, came across this in a search for something completely different - but on first glance looks like it could be useful.
    440 pages - have downloaded myself, registration was simple, but may well be unsubscribing soon.
    Hope it helps
    Gary
  • Damian Green 452 posts 1433 karma points
    Feb 06, 2013 @ 10:54
    Damian Green
    0

    Ah think i might know where you have gone wrong.

    How and where are you calling the partial view?  

    Macros are slightly different beasts in mvc. Have a read of this post by Shannon - he covers this about half way down the post.

    http://umbraco.com/follow-us/blog-archive/2012/10/30/getting-started-with-mvc-in-umbraco-410.aspx

     

     

  • gary 385 posts 916 karma points
    Feb 06, 2013 @ 11:06
    gary
    0

    Hi Damian

    Thanks for reply.

    Calling navigaton partial in a  _layout.cshtml view, with @inherits Umbraco.Web.Mvc.UmbracoTemplatePage

    at the top of both, with the partial in the partial folder. 

    Have used pretty much the same on a couple of builds of 4.10+ and 6RC without an issue, it was just odd that this appeared, but for no reason at all strted working, but the error message remained in VS2012. Bear in mind this is a straight partial, not a macro partial.

    Don't know if that makes it any clearer.

    Regards Gary

  • Matt Taylor 873 posts 2086 karma points
    Feb 06, 2013 @ 12:02
    Matt Taylor
    0

    Thanks for the link to that doc Gary.
    I've downloaded it too.

  • Matt Taylor 873 posts 2086 karma points
    Feb 06, 2013 @ 13:07
    Matt Taylor
    0

    I did find some documentation on creating a basic MVC macro but I think it's for v5.

    It pointed me in the direction of creating your MVC macros via the developer section in the editor,'Partial View Macro Files'.

    If you create your macros there they all start with:

    @inherits Umbraco.Web.Macros.PartialViewMacroPage

    Now you can't have both the @inherits and @model lines as it complains.
    If you remove the @model in favour of the @inherits it will also fail.

     

    The model item passed into the dictionary is of type 'MvcUmbracoTest.Models.MemberLoginModel', but this dictionary requires a model item of type 'Umbraco.Web.Models.PartialViewMacroModel'.

     

    I'm afraid this is where my current understanding fails me.

    Cheers, Matt

Please Sign in or register to post replies

Write your reply to:

Draft