Copied to clipboard

Flag this post as spam?

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


  • Bobby Wallace 29 posts 81 karma points
    Nov 17, 2016 @ 21:06
    Bobby Wallace
    0

    Calling a view with custom model

    I am trying to open a view from a surface controller, but the view responds with:

    The type or namespace name 'propertySearchResultsModel' could not be found (are you missing a using directive or an assembly reference?)

    Model:

    namespace (myNameSpace).Web.UI.Models
    {
        public class PropertySearchResultsModel : RenderModel
        {
            .
            .
            .
        }
    }
    

    Surface Controller:

    public class ApartmentSearchSurfaceController : Umbraco.Web.Mvc.SurfaceController
    {
        [HttpPost]
        public ActionResult ApartmentSearch(ApartmentSearchViewModel model)
        {
            .
            .
            .
            return View("~/Views/searchResults.cshtml", propertySearchResultsModel);
        }
    }
    

    View:

    @using (myNameSpace).Web.UI.Models
    @inherits Umbraco.Web.Mvc.UmbracoViewPage<propertySearchResultsModel>
    @{
        Layout = "siteTemplate.cshtml";
    }       
    

    I have ready other posts on this topic (i.e. https://our.umbraco.org/forum/templating/templates-and-document-types/43193-Current-page-in-view#comment-155630), and I believe I am on the right path, but I'm still struggling. Any help would be greatly appreciated.

  • David Brendel 792 posts 2970 karma points MVP 3x c-trib
    Nov 18, 2016 @ 07:23
    David Brendel
    0

    Hi Bobby,

    I think it's just a typo. Your model type is called PropertySearchResultsModel but you have used it as propertySearchResultsModel in the view. If you make the "p" uppcase it should be fine.

    If not then: how do you call your controller method? and why have you inherited from RenderModel?

    Regards David

Please Sign in or register to post replies

Write your reply to:

Draft