0

I have this code:

$("#allphotos").click(function () {

                $("<div></div>")
                    .addClass("dialog")
                    .appendTo("body")
                    .dialog({
                        close: function() { $(this).remove(); },
                        modal: true,
                        height: 1000,
                        width: 1000
                    })
                    .load("/Home/AllPhotos", data);

            });

And this method:

public ActionResult AllPhotos()
        {
            var listofPhotos =
                RavenSession.Query<ContentPage>()
                    .Where(o => o.Template.ContentPageType == "aPhoto_web.Models.Photography, aPhoto_web")
                    .AsProjection<Photography>()                  
                    .ToList();
            var avm = new AdminViewModel();
            avm.Photographys = listofPhotos;

            return PartialView("_allPhoto", avm.Photographys);


        }

The method returns a list of photographys that i would like the Jquery to display in a dialog. Im pretty sure this line:

.load("/Home/AllPhotos", data);

Is the problem. Any ideas of what to try?

VIEW:

@model aPhoto_web.Models.AdminPages.AdminViewModel
           <h1>Test to see if dialog is empty...and it is</h1>
 @foreach (var item in Model.Photographys)
 {
     <img src="@item.ImgUrl"/>
 }
13
  • What result do you get now? What doesn't work? Commented Aug 1, 2014 at 9:01
  • Does this method is called? Commented Aug 1, 2014 at 9:01
  • The result is an empty dialog. Yes, the method gets called. Commented Aug 1, 2014 at 9:01
  • You are not expecting any parameter in your controller, try just .load("/Home/AllPhotos"); Commented Aug 1, 2014 at 9:12
  • No parameters. Im starting to think that there is a problem wit the view im trying to pass. Even if i harcode in some <p>Hello</p> in it it is empty.. Commented Aug 1, 2014 at 9:14

2 Answers 2

1

Use @Url.Action and remove data from .load() because you don't want to send anything to controller as :

$("#allphotos").click(function () {

            $("<div></div>")
                .addClass("dialog")
                .appendTo("body")
                .dialog({
                    close: function() { $(this).remove(); },
                    modal: true,
                    height: 1000,
                    width: 1000
                })
                .load(@Url.Action("AllPhotos", "Home");
        });

and correct return type of AllPhotos because your partial view is expecting AdminViewModel object.

public ActionResult AllPhotos()
        {
            var listofPhotos =
                RavenSession.Query<ContentPage>()
                    .Where(o => o.Template.ContentPageType == "aPhoto_web.Models.Photography, aPhoto_web")
                    .AsProjection<Photography>()                  
                    .ToList();
            var avm = new AdminViewModel();
            avm.Photographys = listofPhotos;

            return PartialView("_allPhoto", avm); <---------


        }
Sign up to request clarification or add additional context in comments.

3 Comments

what is "data" that you are passing in .load()..??@user2915962
yup =) thats the problem, i do not know how to take care of the result from the method(a view) and pass it to the dialog
@user2915962...there must be a problem in AllPhotos action just check ....in visual studio if you have error in partialview it donot show you have to carefully check for problems...
1

You are not expecting any parameter in your controller, try this in your JavaScript code.

.load("/Home/AllPhotos");

And try this in your view.

return PartialView("_allPhoto", avm);

Your view is expecting AdminViewModel.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.