標籤:
1、建立一個項目,命名為MyLogin,選擇空模板
2、建立一個控制器,命名為Home。
3、為控制器裡的方法Index建立一個(首頁)視圖,命名為Index。
4、在視圖Index裡修改內容
5、添加一個方法命名為Login。
6、為方法Login添加一個視圖命名為Login。
7、更改路由
8、為控制器添加一個有兩個參數的方法Login1,並修改內容。
9、找到content檔案夾及其下面的jquery和ligerui檔案夾,如果沒有,則需要從其他地方先添加content檔案夾及其內容
10、通過拖拽,添加格式
11、更改視圖Login的內容,代碼如下:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>登陸頁面</title>
<script src="~/Content/jquery/jquery-1.9.0.min.js"></script>
<script src="~/Content/ligerui/ligerui.min.js"></script>
<script src="~/Content/ligerui/ligerui.all.js"></script>
<link href="~/Content/ligerui/skins/Aqua/css/ligerui-all.css" rel="stylesheet" />
</head>
<body>
<div id="login"> <!--建立一個id為login的塊---->
<div id="form"></div> <!------塊login內部一個id為form的塊----->
<span id="tip"></span> <!------------一個名為tip的span-------->
</div>
<script type="text/javascript">
$(function () {
//建立表單結構
$("#form").ligerForm({
fields: [
{ display: "使用者名稱", name: "UserName", newline: false, type: "text", },
{ display: "密碼", name: "Password", newline: true, type: "password", }
],
});
//建立交談視窗
$.ligerDialog.open({
target: $("#login"),
title: "Login System",
allowClose: false,
buttons: [
{
text: ‘登入系統‘, onclick: function () { //交談視窗的名字為“登入系統”
var form = liger.get("form");
var data = form.getData(); //表單的值賦給data
if (data.UserName == "" && data.Password == "") { //驗證輸入:輸入為空白的回應
$("#tip").html("使用者名稱和密碼不可為空");
return false;
};
$.post("/Home/Login1", data, function (result) {
if (result.Succ == 1) {
window.document.location.href = "/Home/Index"; //驗證輸入:輸入正確的回應
}
else {
$("#tip").html("使用者名稱或密碼錯誤"); //驗證輸入:輸入錯誤的回應
}
});
}
},
]
});
});
</script>
</body>
</html>
12、調試,查看運行效果
輸入為空白時:
輸入錯誤時:
輸入正確:
asp.net MVC C# LIgerUI實現使用者登入功能login