这里是Model
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace MvcTest2.Models
{
public class User
{
public string Name { get; set; }
public string Password { get; set; }
}
}
这里是控制器:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MvcTest2.Models;
namespace MvcTest2.Controllers
{
public class HomeController : Controller
{
public ActionResult Index()
{
ViewBag.Message = "欢迎使用 ASP.NET MVC!";
return View();
}
public ActionResult About()
{
return View();
}
//显示登录页面
public ActionResult Login()
{
return View();
}
//这个是提交登录的
[HttpPost]
public ActionResult Login(User user)
{
//user中的Name属性和Password属性的值,就是你输入的用户名和密码
return View();
}
}
}
这里是视图。这这里我用了默认的模板:
@model MvcTest2.Models.User
@{
ViewBag.Title = "Login";
}
@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
}
这个视图是生成的,不是手敲的。不要告诉我你不知道这个视图是怎么生成的。
下面是效果图:
这里是后台的监视:
这还用求啊,页面上放俩input,一个用户名一个密码,加个提交按钮不就行了,剩下的交给美工来搞