Reputation: 21
I want to call a view using an enum as a parameter. I made sure to add a PublicJournalEntries view, but I get a 404 page not found every time I run. I have another controller set up with a GetByEnum method that works perfectly, unsure if there is a silly error I made that Im overlooking.
here is the url Im using "https://localhost:44399/JournalEntries/PublicJournalEntries?PublicOrPrivate=1"
this is the code in the controller calling the view
public ActionResult PublicJournalEntries(PublicOrPrivate publicPost)
{
var service = new PublicPostServices();
var model = service.GetPublicPosts(publicPost);
return View(model);
}
here is the .GetPublicPosts method
public IEnumerable<JournalEntryListItem> GetPublicPosts(PublicOrPrivate publicPost)
{
using (var ctx = new ApplicationDbContext())
{
var query =
ctx
.JournalEntries
.Where(x => x.PublicOrPrivate == publicPost)
.Select(
x => new JournalEntryListItem
{
Tag = x.Tag,
Prompt = x.Prompt,
Content = x.Content,
PhotoUrl = x.PhotoUrl,
CreatedUtc = x.CreatedUtc
}
);
return query.ToArray();
}
}
Upvotes: 0
Views: 107
Reputation: 43880
you have to fix your url:
https://localhost:44399/JournalEntries/PublicJournalEntries?publicPost=1"
and the action too:
public ActionResult PublicJournalEntries([FromQuery] PublicOrPrivate publicPost)
Upvotes: 1