Copied to clipboard

Flag this post as spam?

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


  • Jon Dunfee 199 posts 468 karma points
    Apr 03, 2014 @ 23:01
    Jon Dunfee
    0

    Partial Views ... No engine supports the searched locations

    I'm trying to bite the bullet and force myself on the MVC train.  I have a fresh U7.1 solution and created a homepage view template.  In the partials directory, I have a login form.  Basically following the example on Umbraco.TV. Got the model, and surfacecontroller in the appropriate directories.  I go to view the magic like the example, I'm greeted with:

     

    The partial view 'LoginForm' was not found or no view engine supports the searched locations. The following locations were searched:
    ~/Views/LoginFormSurface/LoginForm.aspx
    ~/Views/LoginFormSurface/LoginForm.ascx
    ~/Views/Shared/LoginForm.aspx
    ~/Views/Shared/LoginForm.ascx
    ~/Views/LoginFormSurface/LoginForm.cshtml
    ~/Views/LoginFormSurface/LoginForm.vbhtml
    ~/Views/Shared/LoginForm.cshtml
    ~/Views/Shared/LoginForm.vbhtml


    Do I need to configure something to look in the partials directory?

  • Jon Dunfee 199 posts 468 karma points
    Apr 03, 2014 @ 23:13
    Jon Dunfee
    0

    As a test, I renamed the the ~/views/partials folder to ~/views/shared and the form renders fine.  Rather than create the view in studio, I created it through the back-office just to try something. It created the Partials folder again, but didn't avoid the error.  Now I'm starting to think this is a bug in starting configuration of U7.1 or something.  I might try U6 and see what happens.

  • Jon Dunfee 199 posts 468 karma points
    Apr 03, 2014 @ 23:50
    Jon Dunfee
    0

    This thread offered some insight.  I was using Html.Action("Index","LoginFormSurface") like the video example on Umbraco.TV unsuccessfully. Now, I can get the form to render if I do @Html.Partial("LoginForm", new LoginFormViewModel()).

  • Damian Green 452 posts 1433 karma points
    Apr 04, 2014 @ 00:09
    Damian Green
    0

    I've just upgraded a site from Version 7.0.2 to 7.1 and it appears something has changed.

    The Partials views is no longer getting searched as a location when using a surface controller and calling its GET with 

    @Html.Action("action", "surfacecontrollersurface")

    Also if I move my partial to the Shared folder it find it but now I get an error:

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

    So it looks like the Surface controller is not working as it was in 7.0.2 which looks related to your issue.  The Partials folder has always worked so not sure why its not a valid location any more for Surface Controller partials. It seems ok for standard partials.

     

     

  • Damian Green 452 posts 1433 karma points
    Apr 04, 2014 @ 00:45
    Damian Green
    0

    Just been chatting to Sebatstiaan and it looks like this is a bug.  If you put the View into a folder of the controller without the controller suffix ( a la mvc stylee) it works.

    e.g. ControllerNameSurface 

    And dont forget to delete your Shared view.

    I actually like this way better than it been in the partials.  Its closer to true MVC organisation of files and its easier to spot the custom forms using surface controllers.

     

  • Jon Dunfee 199 posts 468 karma points
    Apr 04, 2014 @ 01:14
    Jon Dunfee
    0

    I'm not so sure I follow.  Here are the files and their location:

    ~/Controllers/LoginFormSurfaceController.cs
    ~/Models/LoginFormViewModel.cs
    ~/Views/Homepage.cshtml (making the @Html.Action("Index", "LoginFormSurface") call)
    ~/Views/Partials/LoginForm.cshtml

    I tried renaming the partial to LoginFormSurface.cshtml and it didn't work.

     

    The partial view 'LoginFormSurface' was not found or no view engine supports the searched locations. The following locations were searched:
    ~/Views/LoginFormSurface/LoginFormSurface.aspx
    ~/Views/LoginFormSurface/LoginFormSurface.ascx
    ~/Views/Shared/LoginFormSurface.aspx
    ~/Views/Shared/LoginFormSurface.ascx
    ~/Views/LoginFormSurface/LoginFormSurface.cshtml
    ~/Views/LoginFormSurface/LoginFormSurface.vbhtml
    ~/Views/Shared/LoginFormSurface.cshtml
    ~/Views/Shared/LoginFormSurface.vbhtml

  • Damian Green 452 posts 1433 karma points
    Apr 04, 2014 @ 01:32
    Damian Green
    0

    INside the Views folder:

    Create a folder called LoginFormSurface

    and put your Login Partial in there.This matches the above route (in the error) 

    ~/Views/LoginFormSurface/LoginFormSurface.cshtml

    Make sure you don thave the login partial in the folder called Shared.

    Just be aware that ths aint currently working as it should! The View normally lives in the Partials folder as in the videos but a bug has crept in by the looks of things.

    Ive created a ticket here:

    http://issues.umbraco.org/issue/U4-4604

     

  • Jon Dunfee 199 posts 468 karma points
    Apr 04, 2014 @ 01:42
    Jon Dunfee
    0

    Gotcha... It did work as you discovered even after renaming the view back to LoginForm.cshtml (and updating the ActionResult). Unfortunately, the folders are not visible in the backoffice so you lose editing capability.  Not good for this client.

  • Damian Green 452 posts 1433 karma points
    Apr 04, 2014 @ 11:06
    Damian Green
    0

    Thats brave letting clients edit the backend! :)

    I also found that the Post also fails so it is a bug that will get fixed and probably back to using the partials folder in 7.1.1

     

  • Jon Dunfee 199 posts 468 karma points
    Apr 04, 2014 @ 19:59
    Jon Dunfee
    0

    Dunno if this confirms what you just said.  I got to the posting part of my login form and receive the following error:

     

    Could not find a Surface controller route in the RouteTable for controller name LoginSurfaceController

    I've accepted the editing component, they don't need to edit these pages.  Here's the directory structure I have currently:

    ~/Controllers/LoginSurfaceController.cs
    ~/Models/LoginFormViewModel.cs
    ~/Views/Homepage.cshtml (making the @Html.Action("Index", "LoginFormSurface") call)
    ~/Views/LoginSurface/LoginForm.cshtml

    If I want to continue with 7.1.0 is there something I could do as a workaround (until fix is out), or should I consider downgrading Umbraco before I get too far vested when we enter content?

  • Jon Dunfee 199 posts 468 karma points
    Apr 05, 2014 @ 04:34
    Jon Dunfee
    0

    I think I figured out why:

    @using (Html.BeginUmbracoForm("Login", "LoginSurfaceController", FormMethod.Post, new { id = "loginForm" })) { ... }

    I removed the word "Controller" and I hit my breakpoint now. I'm learn'n.

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Apr 07, 2014 @ 13:31
    Sebastiaan Janssen
    0

    @Jon Bonus info 1: you don't HAVE to call it SomethingSurfaceController, just like in "regular" MVC you can just call it SomethingController and indeed the convention is not to add the Controller suffix in BeginForm or BeginUmbracoForm.

    Bonus info 2: you can also do a "typed" BeginUmbracoForm, but then you do need the whole class name (as it is properly typed):

    @using (Html.BeginUmbracoForm<LoginSurfaceController>("Login")) {  ... }
    

    I've fixed the Partials error for 7.1.1 (out soon).

    I can't repro the The model item passed into the dictionary is of type 'Umbraco.Web.Models.RenderModel', but this dictionary requires a model item of type 'mytype'" thing, not sure what's going on there.

    My Controller and ViewModel look like this:

    public class ContactController : SurfaceController
    {
        [ChildActionOnly]
        public ActionResult Index()
        {
            return PartialView("ContactForm", new ContactViewModel());
        }
    
        [HttpPost]
        public ActionResult HandleContactForm(ContactViewModel model)
        {
            if (ModelState.IsValid == false)
                return CurrentUmbracoPage();
    
            return RedirectToCurrentUmbracoPage();
        }
    }
    
    public class ContactViewModel
    {
        public string Email { get; set; }
        public string Message { get; set; }
    }
    

    In my Layout (@inherits UmbracoTemplatePage) I call @Html.Action("Index", "Contact")

    And in my Partials folder the Contact view looks like:

    @model ContactViewModel
    
    @using (Html.BeginUmbracoForm<ContactController>("HandleContactForm"))
    {
        @Html.TextBoxFor(x => x.Email)<br />
        @Html.TextAreaFor(x => x.Message)<br />
    
        <input type="submit" value="Send" />
    }
    
  • Jon Dunfee 199 posts 468 karma points
    Apr 08, 2014 @ 17:35
    Jon Dunfee
    0

    After upgrading to 7.1.1 I still received the original error.  I just referenced the view differently after moving the views to the Partials folder and done with it.

    return PartialView("~/Views/Partials/LoginForm.cshtml", new LoginFormViewModel());

     

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Apr 08, 2014 @ 18:19
    Sebastiaan Janssen
    0

    @Jon I can't understand how the problem would still be there. Are you inheriting from SurfaceController? Are you using NuGet and did you upgrade by doing Update-Package or through the NuGet dialogs in VS?

Please Sign in or register to post replies

Write your reply to:

Draft