Я работаю над приложением MVC C # .net Core. Код все еще находится в стадии разработки. Я пытаюсь отобразить изображение, хранящееся в TinyMce, в базе данных SqlServer, и один из моих маршрутов добавляет дополнительный адрес каталога в URL. Итак, я считаю, что это проблема маршрутизации, но я открыт для других идей.
Я искал в Интернете и читал документы Microsoft, но, похоже, не могу определить правильный маршрут.
Этот метод действия работает правильно. Обратите внимание, что здесь нет параметра {id}.
Правильно отображает изображение в списке.
При нажатии View View в браузере создается следующий маршрут ...
локальный: 44353 / изображения / пользователей / MyImage.jpg
[Route("/[controller]/PostList")]
public IActionResult PostList(Guid tagId, Guid authorId, int numPerPage = 10)
{
ICollection<Post> posts;
string currentTag = string.Empty;
string currentAuthor = string.Empty;
if (tagId == Guid.Empty && authorId == Guid.Empty)
{
posts = _blogRepository.GetRecentPosts(numPerPage).ToList();
currentTag = "All posts";
currentAuthor = "All authors";
}
else if (!(tagId == Guid.Empty) && authorId == Guid.Empty)
{
Tag tag = _tagRepository.GetAllTags().FirstOrDefault(t => t.Id == tagId);
posts = _blogRepository.GetPostsByTag(tag).OrderBy(p => p.ModifiedDate).ToList();
currentTag = tag.Content;
currentAuthor = "All authors";
}
else if (!(authorId == Guid.Empty) && tagId == Guid.Empty)
{
Author author = _authorRepository.Authors.FirstOrDefault(a => a.Id == authorId);
posts = _blogRepository.GetPostsByAuthor(author).OrderBy(p => p.ModifiedDate).ToList();
currentTag = "All posts";
currentAuthor = author.AuthorName;
}
else
posts = _blogRepository.GetRecentPosts(numPerPage).ToList();
return View(new PostListViewModel
{
CurrentTag = currentTag,
CurrentAuthor = currentAuthor,
Posts = posts,
AllTags = _tagRepository.GetAllTags().ToList(),
AllAuthors = _authorRepository.Authors.ToList()
});
}
Этот метод действия не отображает изображение
При нажатии View View в браузере создается следующий маршрут ...
локальный: 44353 / Блог / изображения / пользователей / MyImage.jpg
Добавление {id} явно меняет маршрут ...
Я пробовал несколько разных маршрутов безрезультатно ...
[Route("/[controller]/PostDetail/{id}")]
public IActionResult PostDetail(Guid id)
{
var post = _blogRepository.FindCurrentPost(id);
if (post == null)
return NotFound();
return View(new PostDetailViewModel() {
Post = post,
AllAuthors = _authorRepository.Authors.ToList(),
AllTags = _tagRepository.GetAllTags().ToList()
});
}
Хотел бы иметь возможность отображать изображение и иметь правильный маршрут.