Friday, 22 November 2013

How to create Registration and Login Module without Razor View Engine in Asp.Net MVC Part 2

 How to create Registration and Login Module without Razor View Engine in Asp.Net MVC Part 2



Write code in Login.aspx page (Views Part)…………………………………………………….

<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>
<!DOCTYPE html>

<html>
<head runat="server">
<meta name="viewport" content="width=device-width" />
<style>
.login
{
color:#;
background-color:#86dde9;
}
</style>
<title>Login</title>
</head>
<body>
<div class="login" id="login">
<% using (Html.BeginForm())
{ %>
<table width="50%" >
<tr><td></td><td></td></tr>
<tr><td>EmailId</td><td><%:Html.TextBox("emailid")%></td></tr>
<tr><td>Password</td><td><%:Html.Password("password")%></td></tr>
<tr><td> <input type="submit" name="submit" id="submit" value="Login" /> </td>
<td><%:Html.ActionLink("New User?", "Registration")%></td></tr>
<tr><td colspan="2"><div style="color:red;"> <%: ViewData["msg"] %></div></td></tr>
</table>
<%} %>
</div>
</body>
</html>

After design Login Page we will create again Login method with [HttpPost] in  RegistrationLoginController and write code given below…….

public ActionResult Login()
{
return View();
}
[HttpPost]
public ActionResult Login(FormCollection fc)
{
var a = (from f in dd.Employees where f.EmailId == fc["emailid"].ToString() && f.Password == fc["Password"].ToString() select f).FirstOrDefault();
if (a != null)
{
Session["name"] = (from m in dd.Employees where m.EmailId == fc["emailid"] select m.Name).FirstOrDefault();
return RedirectToAction("WelCome");
}
else
{
ViewData["msg"] = "your emailid and  password is  not  match";
}
return View();

}



Write code in WelCome.aspx Page(ViewsPart)…………

<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<!DOCTYPE html>

<html>
<head runat="server">
<meta name="viewport" content="width=device-width" />
<title>WelCome</title>
</head>
<body>
<div>
<% using (Html.BeginForm())
{ %>
<table>
<tr><td><h4>Welcome to my First MVC website <%:Session["name"]%>.</h4></td></tr>

</table>
<%} %>

</div>
</body>
</html>

// this method for Welcome Page
public ActionResult WelCome()
{
return View();
}


0 comments:

Post a Comment