0

Controller:

 public ActionResult Univ(short id) {

        var db = new DbEntities();

        var query = from u in db.Universitates
                     join f in db.Facultates on u.IDUniv equals f.IDUniv
                     join s in db.Specializares on f.IDFac equals s.IDFac
                     where u.IDUniv == id
                     select new SearchViewModel
                     {
                         NumeUniv = u.NumeUniv,
                         OrasUniv = u.OrasUniv,
                         IDUniv = u.IDUniv,
                         NumeFac = f.NumeFac,
                         NumeSpec = s.NumeSpec
                     };

        return View(query);
    }

View:

@model Proj.Models.SearchViewModel

<h3>@Model.NumeUniv</h3>

I have the following error:

The model item passed into the dictionary is of type
'System.Data.Entity.Infrastructure.DbQuery`1[Proj.Models.SearchViewModel]',
but this dictionary requires a model item of type 'Proj.Models.SearchViewModel'.

Why is this?

1 Answer 1

1

The query is returning a enumerable list of SearchViewModel while your view is only looking for a single SearchViewModel.

Please try return View(query.First());

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

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.