A
A
Alexxxey_enot2021-03-18 15:42:56
ASP.NET
Alexxxey_enot, 2021-03-18 15:42:56

Featured products not showing up?

public class HomeController : Controller
    {
        private readonly IAllRealty _realtyRep;

        public HomeController(IAllRealty realRep)
        {
            _realtyRep = realRep;
        }
        public ViewResult Index()
        {
            var homeRealty = new HomeViewModel
            {
                favRealty = _realtyRep.getFavRealty
            };
            return View(homeRealty);
        }
    }


public interface IAllRealty
    {
        IEnumerable<Realty> Realty { get; }
        IEnumerable<Realty> getFavRealty { get; }
        Realty getObjectRealty(int realtyId);
    }


public class Realty
    {
        public int id { set; get; }
        public string room { set; get; }
        public string floor { set; get; }
        public string squares { set; get; }
        public string adress { set; get; }
        public string metro { set; get; }
        public string img { set; get; }
        public uint price { set; get; }
        public string shortDesc { set; get; }
        public string longDesc { set; get; }
        public string phone { get; set; }
        public bool isFavourite { set; get; }
        public int categoryID { set; get; }
        public virtual Category Category { set; get; }
    }


class DBObjects{
        public static void Initial(AppDBContent content)
        {

            if (!content.Category.Any())
                content.Category.AddRange(Categories.Select(c => c.Value));

            if (!content.Realty.Any())
            {
                content.AddRange(
                     new Realty
                     {
                         room = "2-комнатная",
                         floor = "4 этаж из 15",
                         squares = "79м²",
                         metro = "м.Алабинская",
                         adress = "улица Митерева, дом 85, кв 128",
                         img = "img/home.jpg",
                         price = 3400000,
                         shortDesc = "Очень хорошая квартира.",
                         longDesc = "Дом находится на южной стороне",
                         phone = "12345678900",
                         isFavourite = true,
                         Category = Categories["Вторичка"]
                     },
                    new Realty
                    {
                        room = "1-комнатная",
                        floor = "17 этаж из 38",
                        squares = "49м²",
                        metro = "м.Гагарина",
                        adress = "улица Ленинградская, дом 17, кв 350",
                        img = "img/home2.webp",
                        price = 2600000,
                        shortDesc = "Очень хорошая квартира.",
                        longDesc = "Дом находится на южной стороне",
                        phone = "12345678900",
                        isFavourite = false,
                        Category = Categories["Новостройка"]
                    },
                    new Realty
                    {
                        room = "3-комнатная",
                        floor = "19 этаж из 24",
                        squares = "140м²",
                        metro = "м.Победа",
                        adress = "улица Дальняя, дом 57, кв 192",
                        img = "img/home3.jfif",
                        price = 5600000,
                        shortDesc = "Очень хорошая квартира.",
                        longDesc = "Дом находится на южной стороне",
                        phone = "12345678900",
                        isFavourite = true,
                        Category = Categories["Новостройка"]
                    },
                     new Realty
                     {
                         room = "1-комнатная",
                         floor = "30 этаж из 30",
                         squares = "51м²",
                         metro = "м.Спортивная",
                         adress = "улица Московская шоссе, дом 10, кв 350",
                         img = "img/home4.webp",
                         price = 6600000,
                         shortDesc = "Очень хорошая квартира.",
                         longDesc = "Дом находится на южной стороне",
                         phone = "12345678900",
                         isFavourite = false,
                         Category = Categories["Вторичка"]
                     },
                      new Realty
                      {
                          room = "офис",
                          floor = "77 этаж из 78",
                          squares = "251м²",
                          metro = "м.Московское",
                          adress = "улица Московская шоссе, дом 10, офис 350",
                          img = "img/office.jpg",
                          price = 6600000,
                          shortDesc = "Очень хороший офис.",
                          longDesc = "Офис с хорошим ремонтом",
                          phone = "12345678900",
                          isFavourite = false,
                          Category = Categories["Аренда"]
                      }
                    );
            }
            content.SaveChanges();

        }
}


public class HomeViewModel
    {
        public IEnumerable<Realty> favRealty { get; set; }
    }


@model HomeViewModel


<h2>Избранная недвижимость</h2>
<div class="row mt-5 mb-4">
    @{
        foreach (Realty realt in Model.favRealty)
        {
            @Html.Partial("AllRealty", realt)
        }

    }
</div>


60534b7176f80867111881.png
by default, it is loaded when specifying the address of the basket, an error is detected,
despite the fact that I wrote the name of the controller and the method correctly, still an error
60534bc4aa2a1849412924.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Roman, 2021-03-19
@Alexxxey_enot

Your controller can't find the view. Did you read the exception text? There, even the paths are written where the view should lie.

D
d-stream, 2021-03-18
@d-stream

No, well, I understand, there were times when you had to take a form in one building, fill it out, hand it in in another building, the next day receive punched cards and carry them to the EC in another building, and the next day receive a printout ... But now F9-F10 is the happiness of step-by-step debugging right on the go...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question