使用MVC3登录后,在网格中显示用户信息 [英] Display the user Information in a grid after logging in using MVC3

查看:82
本文介绍了使用MVC3登录后,在网格中显示用户信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我是MVC3的新手,已经使用MVC3架构编写了用于登录的代码,一切正常,现在我想在他登录后显示用户信息.如何在MODEL中开发代码,我想使用linq和Enity框架获得结果.

Hi all I am new to MVC3 have written a code for login using MVC3 architecture every thing works fine, now I would like to display the user information after he logs in. How can I develop the code in MODEL , I would like to get the results with out using linq and Enity framework.

[HttpPost, ValidateInput(false)]
    public ActionResult LogOn(Login model)
    {
        if (ModelState.IsValid)
        {
            if (model.IsUserExist(model.EmailId, model.Password))
            {
               ViewBag.UserName = model.EmailId;
              //I tried this which didn't worked
                 //if (model.select(model.EmailId))
                //{
                  //  return RedirectToAction("Display", "Home");
               // }
               // here I would like to code to show the data of the one who logged in with Edit, delete options
            }
            else
            {
                ModelState.AddModelError("", "EmailId or Password Incorrect.");
            }
        }
        return View(model);
    }

推荐答案

如果您使用的是Forms身份验证,则应该可以使用FormsAuthentication.SetAuthCookie:

http://msdn.microsoft.com/en-us/library/system.web.security.formsauthentication.setauthcookie.aspx [ ^ ]

当您使用return RedirectToAction("Display", "Home")重定向到首页时,显示"视图可以使用HttpContext.Current.User.Identity.Name显示名称:

http://msdn.microsoft.com/en-us/library/system. web.httpcontext.user.aspx [ ^ ]
If you''re using Forms authentication, you should be able to use FormsAuthentication.SetAuthCookie:

http://msdn.microsoft.com/en-us/library/system.web.security.formsauthentication.setauthcookie.aspx[^]

And when you redirect to home using return RedirectToAction("Display", "Home"), your Display view can use HttpContext.Current.User.Identity.Name to display the name:

http://msdn.microsoft.com/en-us/library/system.web.httpcontext.user.aspx[^]


这篇关于使用MVC3登录后,在网格中显示用户信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆