Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/25.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
C# 带有空页面的部分视图ASP MVC 3_C#_Sql Server_Asp.net Mvc 3_Visual Studio 2010 - Fatal编程技术网

C# 带有空页面的部分视图ASP MVC 3

C# 带有空页面的部分视图ASP MVC 3,c#,sql-server,asp.net-mvc-3,visual-studio-2010,C#,Sql Server,Asp.net Mvc 3,Visual Studio 2010,我正在使用C#和SQLServer2005开发一个ASP.NETMVC3应用程序。我使用实体框架,采用代码优先的方法 我有一个用于登录(连接)的界面,该界面与我的基础相关,其中我有一个用户表(包含Login+密码) 这是connexion:LogonPartial.acx(从UserViewModel强类型化的部分视图)的视图 欢迎光临! [ ] [ ] 连接成功时:我只有“登录”链接。 连接失败时:页面为空 这是控制器: [ChildActionOnly] public

我正在使用C#和SQLServer2005开发一个ASP.NETMVC3应用程序。我使用实体框架,采用代码优先的方法

我有一个用于登录(连接)的界面,该界面与我的基础相关,其中我有一个用户表(包含Login+密码)

这是connexion:LogonPartial.acx(从UserViewModel强类型化的部分视图)的视图


欢迎光临!
[  ]
[  ]
连接成功时:我只有“登录”链接。 连接失败时:页面为空

这是控制器:

[ChildActionOnly]
        public ActionResult LogedInUser()
        {
            var user = new UserViewModel();
            if (Request.IsAuthenticated)
            {
                user.Nom_User = User.Identity.Name;
            }
            return PartialView(user);
        }
private GammeContext db = new GammeContext();
        [AcceptVerbs(HttpVerbs.Post)]
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings",
            Justification = "Needs to take same parameter type as Controller.Redirect()")]
        public ActionResult LogedInUser(string Matricule, string passWord, bool rememberMe, string returnUrl)
        {
            if (!ValidateLogOn(Matricule, passWord))
            {
                return Connection(Matricule, passWord, returnUrl);
            }

            //FormsAuth.SignIn(Matricule, rememberMe);

            if (!String.IsNullOrEmpty(returnUrl))
            {
                return Redirect(returnUrl);
            }
            else
            {
                return RedirectToAction("Index", "Home");
            }
        }

        public ActionResult Connection(string Matricule, string passWord, string returnUrl)
        {
            List<User> users = db.Users.ToList();
            ActionResult output = null;

            if (users.Any())
            {
                foreach (User u in users)
                {
                    if ((u.Matricule == Matricule) && (u.passWord == passWord))
                    {
                        output = View();
                    }
                }
            }
            else
            {
                output = Redirect(returnUrl);
            }

            return output;
        }
[ChildActionOnly]
公共操作结果日志用户()
{
var user=new UserViewModel();
如果(请求已验证)
{
user.Nom_user=user.Identity.Name;
}
返回PartialView(用户);
}
私有GammeContext db=新GammeContext();
[接受动词(HttpVerbs.Post)]
[System.Diagnostics.CodeAnalysis.SuppressMessage(“Microsoft.Design”、“CA1054:UriParametersShouldNotBeStrings”,
对齐=“需要采用与控制器相同的参数类型。重定向()”)
公共操作结果日志用户(字符串矩阵、字符串密码、bool rememberMe、字符串返回URL)
{
如果(!ValidateLogOn(矩阵,密码))
{
返回连接(矩阵、密码、返回URL);
}
//形式符号(矩阵,记忆);
如果(!String.IsNullOrEmpty(returnUrl))
{
返回重定向(returnUrl);
}
其他的
{
返回重定向到操作(“索引”、“主页”);
}
}
公共操作结果连接(字符串矩阵、字符串密码、字符串返回URL)
{
List users=db.users.ToList();
ActionResult输出=null;
if(users.Any())
{
foreach(用户中的用户u)
{
如果((u.Matricule==矩阵)和&(u.passWord==密码))
{
输出=视图();
}
}
}
其他的
{
输出=重定向(返回URL);
}
返回输出;
}

我看不出您在哪里验证用户?如果您尝试以下方法:

if (!ValidateLogOn(Matricule, passWord))
{       
   return Connection(Matricule, passWord, returnUrl);
}

// user is valid, authenticate
FormsAuthentication.SetAuthCookie(Matricule, true);

您的ActionLink需要正确更新

它应采用上述示例中的格式:

<%: Html.ActionLink("Text on UI", "MethodNameInController", "ControllerName") %>

您还没有完成上面的操作-您的操作链接在控制器中没有方法。我还建议您阅读本教程-


首先,您甚至从未使用过您的UserViewModel。其次,我不确定你所说的“连接成功”(我想是登录成功)是什么意思,但如果是这种情况,你没有正确验证你的用户。是的,登录成功这就是我的意思。我认为身份验证是可以的,因为当我将存在于基中的值放入时,它会将我带到一个带有登录链接的页面。然而,在相反的情况下,它会把我带到一个空页面。这个逻辑应该在你的控制器中,而不是你的页面中。您的帐户控制器中的代码是什么样子的?@KOL请看一下edit我看不到您的操作链接在代码中调用的登录方法或注销方法您添加了答案谢谢,但“密码”未被接受(在当前上下文中不存在),,,,,我用“密码”尝试,,,抱歉,第二个参数是布尔值(持久性),请检查我的editOh。没问题,我更正了,我尝试了一下,但结果是一样的!对不起,你能看看我上面的对话吗,我想问题就在那里!谢谢我以前读过这首芭蕾舞曲(这不是第一次有人向我推荐这首芭蕾舞曲),,我是初学者,我知道我应该在ActionLink中加入什么!第一个错误是因为我忘了改变它!请,,,我认为问题不在那里,,,因为登录用户的名字也没有出现!!
<%: Html.ActionLink("Text on UI", "MethodNameInController", "ControllerName") %>