这是我的个人资料页面。控制器在那里。如果登录成功,我想去个人资料,如果不成功,我想去页面辞职。请给我建议答案。
@{
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");
}
}
}
}
答案 0 :(得分:0)
假设ReSignIn和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");
}
}
希望这会有所帮助。享受!!