Asp.MVC4 应用程序中的错误.联合国处理的异常



这是我的个人资料页面。控制器在那里。如果登录成功,我想转到个人资料,如果登录不成功,我想在页面中辞职。请给我建议答案。

@{
    ViewBag.Title = "Profile!";
}

<script src="~/Scripts/Profile.js"></script>
<link href="~/Content/Profile.css" rel="stylesheet" />
<form class="form" name="form-CreateGroup" action="/CreateGroup/CreateGroup/@Model.Uid" method="post">
    <div>
        <input type="submit" id="CreateGroup" name="CreateGroup" value="Create Group" /><p> <span id="comments">Create your own groups.</span></p>
    </div>
</form>
<form class="form" name="form-SearchGroup" action="/Profile/SearchGroup" method="post">
    <div>
        <input type="submit" id="SearchGroup" name="SearchGroup" value="Search Group" /><p> <span id="comments">Search Groups to join them.</span></p>
    </div>
</form>
<form class="form" name="form-ViewGroups" action="/Profile/ViewGroups" method="post">
    <div>
        <input type="submit" id="ViewGroup" name="ViewGroup" value="View Groups" /><p> <span id="comments">View Groups you have already joined.</span></p>
    </div>
</form>
<form class="form" name="form-DeleteGroup" action="/Profile/DeleteGroup" method="post">
    <div>
        <input type="submit" id="DeleteGroup" name="DeleteGroup" value="Delete Group" /><p> <span id="comments">Delete Groups you are managing.</span></p>
    </div>
</form>

这是我的控制器,如果帐户存在,我想在其中引导个人资料,如果帐户不存在,则导致辞职。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Project_Buddy.Models;
namespace Project_Buddy.Controllers
{
    public class SignInController : Controller
    {
        //
        // GET: /Signip/
        Database1Entities db = new Database1Entities();
        public ActionResult Index()
        {
            return View();
        }
        public ActionResult SignIn()
        {
            return View();
        }
        public ActionResult validation()
        {
            var email =Request["email"];
            var pas = Request["password"];
            IQueryable<User> record=null;
            record = (db.Users.Where(x=>x.email==email));
            if (record==null)
            {
                return Redirect("/ReSignIn/ReSignIn");
            }
            else
            {
                return Redirect("/Profile/Profile");
            }
        }

    }
}

假设重新登录和配置文件是不同的控制器,您可以尝试以下操作:

public ActionResult validation()
{
    var email = Request["email"];
    var pas = Request["password"];
    IQueryable<User> record = null;
    record = (db.Users.Where(x => x.email == email));
    if (record == null)
    {
        return RedirectToAction("ReSignIn", "ReSignIn");
    }
    else
    {
        return RedirectToAction("Profile", "Profile");
    }
}

希望这有帮助。享受!!

最新更新