So i am requesting some data from the database and want to put it in a list, but the problem is that how to give the variable only the "pt (pagetemplates)" and not the "wl" that i need for the WHERE clause
public async Task<IActionResult> PageAdd()
{
//Test WebsiteLanguageId
var WebsiteLanguageId = 1;
var UserId = _userManager.GetUserId(User);
var PT = await _context.WebsiteLanguages.Join(_context.Websites, wl => wl.WebsiteId,
w => w.Id, (wl, w) => new { wl, w })
.Join(_context.PageTemplates, x => x.w.Id,
pt => pt.WebsiteId, ( x, pt) => new { x.wl, pt })
.Where(x => x.wl.WebsiteId == WebsiteLanguageId)
.OrderBy(x => x.pt.Name).ToListAsync();
return View(PT);
}And another problem i have is that if i send the PT variable (also with only the pagetemplates and not with website languages) to the page i get a error like this:
InvalidOperationException: The model item passed into the ViewDataDictionary is of type 'System.Collections.Generic.List`1[cms.Entity.PageTemplates]', but this ViewDataDictionary instance requires a model item of type 'cms.Models.PageViewModels.PageAddViewModel'.
Here are some codes that will be used:
PageTemplates.cs
using System;
using System.Collections.Generic;
namespace cms.Entity
{
public partial class PageTemplates
{
public int Id { get; set; }
public int WebsiteId { get; set; }
public string Name { get; set; }
}
}
PageAddViewModel.cs
using System.ComponentModel.DataAnnotations;
using cms.Entity;
using System.Collections;
using System.Collections.Generic;
namespace cms.Models.PageViewModels
{
public class PageAddViewModel
{
public Pages Pages { get; set; }
public PageTemplates PageTemplates { get; set; }
public PageTemplateFields PageTemplateFields { get; set; }
public IEnumerable<PageTemplates> PageTemplatesIEnumerable { get; set; }
}
}PageAdd.cshtml
@model PageAddViewModel
@{
ViewData["Title"] = "Add page";
}
@foreach (var i in Model.PageTemplatesIEnumerable)
{
<option value="@Html.DisplayFor(modelItem => i.Id)">@Html.DisplayFor(modelItem => i.Name)</option>
}Is there someone that know how to fix this 2 problems