Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 3 如何在一个简单的博客站点中为登录用户显示特定的帖子?_Asp.net Mvc 3_Linq_List - Fatal编程技术网

Asp.net mvc 3 如何在一个简单的博客站点中为登录用户显示特定的帖子?

Asp.net mvc 3 如何在一个简单的博客站点中为登录用户显示特定的帖子?,asp.net-mvc-3,linq,list,Asp.net Mvc 3,Linq,List,场景是,我有一个简单的Post表,只有标题和故事。发布新帖子后,我希望使用我的查看页面显示帖子。我已编写了显示帖子的方法,如下所示: \\Post is the class name & item is the obj to bind it from the view form. public List<Post> ViewPost(Post item) { using(var context=new TourBlogEntities1())

场景是,我有一个简单的Post表,只有标题和故事。发布新帖子后,我希望使用我的查看页面显示帖子。我已编写了显示帖子的方法,如下所示:

  \\Post is the class name & item is the obj to bind it from the view form.
public List<Post> ViewPost(Post item)
    {
        using(var context=new TourBlogEntities1())
        {
            var post= from s in context.Posts
                      where s.PostID=item.PostID //showing error here.
                      select s;

            return post.ToList<Post>();
        }
    }
\\Post是类名,item是从视图窗体绑定它的对象。
公共列表视图发布(发布项目)
{
使用(var context=new tourblogenties1())
{
var post=来自context.Posts中的s
其中s.PostID=item.PostID//在此处显示错误。
选择s;
返回邮政编码ToList();
}
}
我收到一个错误,提示“无法将lambada表达式转换为string类型,因为它不是委托类型”


需要做什么?另外一些信息也很有用,比如我在post表中有一个字段名userid,我想使用日志信息自动填充它。我该怎么做?谢谢。

在LINQ查询中替换:

where s.PostID = item.PostID 
与:


where
LINQ运算符需要一个布尔条件而不是赋值。

OPS!那太傻了!我只是没注意到!谢谢你,伙计!你能帮我提供其他信息吗?我不明白你在问题的第二部分问什么。好的…用户必须登录才能发布,所以他提交了用户名和密码才能登录,现在当他想发布故事时,我想通过登录信息知道用户名。一般来说,我需要知道当前登录用户的基本信息。我该怎么做?顺便说一句,我使用了表单身份验证。您可以在控制器操作中使用
User.Identity.Name
检索当前经过身份验证的用户名。确保控制器操作使用
[Authorize]
属性修饰,以确保只有经过身份验证的用户才能调用它。我确实将post操作方法标记为Authorize。谢谢你的帮助。
where s.PostID == item.PostID