MVC Routing Settings App_start/routeconfig.cs
Using system;using system.collections.generic;using system.linq;using system.web;using System.Web.Mvc;using System.web.routing;namespace mvclogin{public class Routeconfig {public static void RegisterRoutes ( RouteCollection routes) { routes. Ignoreroute ("{resource}.axd/{*pathinfo}"); Routes. MapRoute ( name: "Default", URL: "{controller}/{action}", defaults:new {controller = "Login", action = " Index "} );}}}
Controller Controllers/logincontroller.cs
Using system;using system.collections.generic;using system.linq;using system.web;using System.Web.Mvc;using System.data;using system.data.sqlclient;namespace mvclogin.controllers{public class Logincontroller:controller { GET:/login/public actionresult Index () {return View (); } public ActionResult Add () {String Name = request["UserName"]. ToString (); String Pass = request["Password"]. ToString (); String sql = "INSERT into T_login values (@userName, @pass)"; int i = sqlhelper.executenonquery (sql, New SqlParameter ("UserName", Name), New SqlParameter ("Pass", pass)); Return Content ("OK"); Public ActionResult Login () {return View ("login"); Public ActionResult Loginresponse () {String Name = request.form["UserName"]. ToString (); String Pass = request.form["Password"]. ToString (); String sql = "SELECT * from T_login where [email protected]"; DataTable dt = sqlhelper.executedatatable (sql, New SqlParameter ("name", name)); if (dt. Rows.Count <= 0) {viewdata["Message"] = "user name does not exist"; Return View ("Login"); } if (dt. Rows.Count > 1) {viewdata["Message"] = "big thing is not good, query out more than one data"; Return View ("Login"); } if (dt. rows[0]["Password"]. ToString () = Pass) {viewdata["Message"] = "wrong password"; Return View ("Login"); } return Content ("Congratulations ~ landing success"); } }}
View
Index View Views/login/index.aspx
<%@ page language= "C #" inherits= "system.web.mvc.viewpage<dynamic>"%><! DOCTYPE html>
Login View Views/login/login.aspx
<%@ page language= "C #" inherits= "system.web.mvc.viewpage<dynamic>"%><! DOCTYPE html>
MVC Request Processing Response "User Login"