Copied to clipboard

Flag this post as spam?

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


  • Casper Andersen 126 posts 508 karma points
    Aug 03, 2015 @ 09:03
    Casper Andersen
    0

    Using Parse together with Umbraco SurfaceController

    Hi there, i have to get some data from a Parse database into a view in Umbraco. and i am havĂ­ng some problems that i hope someone can help me with.

    Firstly i am using a SurfaceController and i have an action called List that looks like this

    public async Task<ActionResult> List()
            {
                var query = new ParseQuery<Property>().WhereNotEqualTo("ObjectId", string.Empty);
                IEnumerable<Property> results = await query.FindAsync();
                return PartialView("~/Views/Partials/List.cshtml", results);
            }
    

    i can see using debug mode in Visual Studio that i get the data i need, but when i try and call my PartialView like i am sending in my results i get this problem

    The model item passed into the dictionary is of type 'System.Collections.ObjectModel.ReadOnlyCollection`1[Property]', but this dictionary requires a model item of type 'Property'.
    

    Property is a Model

    and my partialview for the moment just looks like this

    @inherits Umbraco.Web.Mvc.UmbracoViewPage<Property>
    

    I hope someone has the answer to this since it really annoys me.

  • Casper Andersen 126 posts 508 karma points
    Aug 04, 2015 @ 20:11
    Casper Andersen
    0

    I hope someone has the knowledge who can help me. Even if you dont understand the way i am doing it, if you know a way of using async in a surfaceController please tell me

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Aug 04, 2015 @ 21:32
    Sebastiaan Janssen
    0

    You're returning a IEnumerable<Property> but your view expects a Property.

    So the partial should probably be: @inherits Umbraco.Web.Mvc.UmbracoViewPage<IEnumerable<Property>>

  • Casper Andersen 126 posts 508 karma points
    Aug 05, 2015 @ 06:16
    Casper Andersen
    0

    Ok that was a mistake on my end, ofc i tried that many times, but i forgot to include it in this thread since i was messing around a lo with the view and the controller method

    But if i do that, then i get this problem

    The model item passed into the dictionary is of type 'System.Collections.ObjectModel.ReadOnlyCollection`1[vurdernu.Models.Property]', but this dictionary requires a model item of type 'vurdernu.Models.Property'.
    

    And if i try and put System.Collections.ObjectModel.ReadOnlyCollection

    so it looks like this

    @inherits Umbraco.Web.Mvc.UmbracoViewPage<System.Collections.ObjectModel.ReadOnlyCollection<vurdernu.Models.Property>>
    

    then i get

    HttpServerUtility.Execute blocked while waiting for an asynchronous operation to complete.
    

    Any ideas how i get passed this ?

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Aug 05, 2015 @ 06:46
    Sebastiaan Janssen
    0

    Don't make it async :-)

    I'm an async virgin, hard to get my head around it and problems like this. As far as I understand it you always have to have something await an async call and I doubt that views have a way of awaiting. If you think about it that makes sense, a view is rendering your html, it can't wait for your data to arrive whenever it wants (also defeats the purpose of async if you're going to synchronously wait for data to arrive before starting the render).

    I could be way off, as I said I am very inexperienced in async!

  • Casper Andersen 126 posts 508 karma points
    Aug 05, 2015 @ 06:57
    Casper Andersen
    0

    Ok so now my controller method looks like this

    public ActionResult List()
            {
                var query = new ParseQuery<Property>().WhereNotEqualTo("ObjectId", string.Empty);
                var results = query.FindAsync();
                return PartialView("~/Views/Partials/List.cshtml", results);
            }
    

    and my view now looks like this

    @inherits Umbraco.Web.Mvc.UmbracoViewPage<IEnumerable<vurdernu.Models.Property>>
    

    and i get the error

    The model item passed into the dictionary is of type 'System.Threading.Tasks.UnwrapPromise`1[System.Collections.Generic.IEnumerable`1[vurdernu.Models.Property]]', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable`1[vurdernu.Models.Property]'.
    
Please Sign in or register to post replies

Write your reply to:

Draft