ASP.NET MVC登陆界面(结合bootstrap)

这篇博客展示了如何在ASP.NET MVC项目中结合Bootstrap创建一个登录界面。首先,介绍了效果图,然后详细讲解了两个主要部分:一是index.cshtml文件的创建和代码实现,包括在HomeController中为Index函数配置视图;二是HomeController的详细内容,阐述了相关代码逻辑。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

效果图

这里写图片描述

一、index.cshtml

~/home/index.cshtml:新建一个HomeController(由~/App_Start/RouteConfig.cs文件可知‘home’是默认路由),为Index函数建立一个视图‘index.cshtml’

1. code

@{
Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Index</title>
    @* bootstrap引入 *@
    <link href="~/Content/bootstrap.min.css" rel="stylesheet" />
</head>
<body>
    <div class="container">
        <div class="row">
            @* action属性值是接收页面参数的函数名称 *@
            <form action="/home/Regist">
                <div class="form-group">
                    @* for的用途是:当点击“用户名”时,光标会到“name”的输入框 *@
                    <label for="name">用户名</label>
                    @* name属性值是Regist的参数 *@
                    <input type="text" class="form-control" id="name" placeholder="输入用户名" name="username">
                </div>
                <div class="form-group">
                    <label for="password">密码</label>
                    <input type="password" class="form-control" id="password" placeholder="输入密码" name="password">
                </div>
                <div class="form-group">
                    <input type="submit" class="btn btn-default" value="注册">
                </div>
            </form>
        </div>
    </div>
    @* 引入bootstrap(顺序不能变) *@
    <script src="~/Scripts/jquery-1.9.1.min.js"></script>
    <script src="~/Scripts/bootstrap.min.js"></script>
</body>
</html>

二、HomeController

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace WebApplication1.Controllers
{
    public class HomeController : Controller
    {
        // GET: Home
        public ActionResult Index()
        {
            return View();
        }

        // 与~/home/index.cshtml中表单参数保持一致
        public ActionResult Regist(String username,String password)
        {
            return Content(username+password);
        }
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值