How to Add new view file?

Topics: Core, Customizing Orchard, General, Installing Orchard, Localization, Troubleshooting
May 2, 2013 at 10:14 AM
Edited May 2, 2013 at 12:29 PM
Hi,
I have added a new action blogger in blogcontroller under Orchard.Blogs module. I have added a view file under view/blog/blogger.cshtml. But the view does not display. It shows the below error.

__Error:
Oops. Something went wrong ... sorry

An unhandled exception has occurred and the request was terminated. Please refresh the page. If the error persists, go back
__

Action Code:

public ActionResult Blogger(string ownerid)
    {


        var posts = _blogPostService.bloggers(ownerid);
        Bloggers bc = new Bloggers();
        bc.BloggersPostList(posts); 
        return View("Blogger");
    }
Bloggers Model:
using Orchard.ContentManagement;
using Orchard.ContentManagement.Aspects;
using System.Collections.Generic;
using Orchard.Blogs;
using System.Linq;
using System.Transactions;
namespace Orchard.Blogs.Models
{
public class Bloggers
{
    public List<PostDetails> postDetails { get; set; }
    BlogDataContext bc = new BlogDataContext();
    public List<blog_Orchard_Users_UserPartRecord> BloggersList()
    {

        using (var scope = new TransactionScope(TransactionScopeOption.Suppress))
        {
            var bloggerList = (from blogger in bc.blog_Orchard_Users_UserPartRecords select blogger).ToList();
            return bloggerList;
        }
    }

    public string TagName(int? blogId)
    {
        using (var scope = new TransactionScope(TransactionScopeOption.Suppress))
        {
            int? tagId = (from tag in bc.blog_Orchard_Tags_ContentTagRecords where tag.TagsPartRecord_Id == blogId select tag.TagRecord_Id).FirstOrDefault();
            string tagName = (from tag in bc.blog_Orchard_Tags_TagRecords where tag.Id == tagId select tag.TagName).FirstOrDefault();

            return tagName;
        }
    }
    public List<int> CommentCount(int? id)
    {
        using (var scope = new TransactionScope(TransactionScopeOption.Suppress))
        {
            List<int> commentCount = (from comment in bc.blog_Orchard_Comments_CommentPartRecords where comment.CommentsPartRecord_id == id && comment.Status == "Approved" select comment.Id).ToList();
            return commentCount;
        }
    }

    public List<PostDetails> BloggersPostList(IEnumerable<BlogPostPart> blogPostPart)
    {

        List<PostDetails> postDetailsList= new List<PostDetails>();

        PostDetails postDetail = new PostDetails();
        foreach (var post in blogPostPart)
        {
            int? id=0;
            using (var scope = new TransactionScope(TransactionScopeOption.Suppress))
            {
                id = (from postInfo in bc.blog_Title_TitlePartRecords where postInfo.Title == post.Title select postInfo.ContentItemRecord_id).FirstOrDefault();

            }

            string tagName = tagName = TagName(id);
            List<int> commentCount = CommentCount(id);
            postDetail.Title = post.Title;
            postDetail.Comments = commentCount.Count();
            postDetail.Body = post.Text;
            postDetail.PostedBy = post.Creator.UserName;
            postDetailsList.Add(postDetail);
        }
        postDetails.AddRange(postDetailsList);
        return postDetailsList;
    }

}
public class PostDetails
{
    public string Title { get; set; }
    public string Body { get; set; }
    public string Tag { get; set; }
    public string PostedBy { get; set; }
    public int Comments { get; set; }
}
}
Can you please let me know how to resolve this issue?
Developer
May 2, 2013 at 2:02 PM
When encountering such exception always take a look at the log to see the full exception or even better, attach a debugger and watch the exception directly. Knowing the exception helps a lot to identify the exact problem.
Also it's better not to modify built-in code. Rather add your own controller in your own module.