【发布时间】:2016-06-15 06:52:27
【问题描述】:
作为一些背景,我是通过 VB6 和 VB.Net 来的,现在我正在尝试使用 C# 的 Bootstrap/MVC,所以请原谅这些查询......我已经搜索过并且也在 YouTube 上,但有点挣扎。我的方法是错误的请告诉我!
目标: 要运行的存储过程,在这种情况下,确认用户名和密码是否正确。我想在以后的存储过程中添加插入/编辑。
问题: 当我在网站上运行代码时,我没有收到任何错误或结果。在调试模式下,我得到:
Unhandled exception at line 133, column 5 in http://localhost:49647/Account/Login
0x800a1391 - JavaScript runtime error: '$' is undefined
想法 我不是 JS 程序员,但会假设我需要以某种方式添加一些东西来“暗淡”价值?看着0x800a1391 - JavaScript runtime error: 'jQuery' is undefined 我可能需要打电话?
User.cs
using System;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
namespace Login.BL
{
public class User
{
public int UserID { get; set; }
//[Required]
public int Username { get; set; }
//[Required]
public int UserPassword { get; set; }
}
public class UserBusinessLogic
{
string conStr = ConfigurationManager.ConnectionStrings["myTaylorWoodrowSQL"].ConnectionString;
public int CheckUserLogin(User User)
{
//Check the user is valid!!!!
using (SqlConnection conObj = new SqlConnection(conStr))
{
SqlCommand comObj = new SqlCommand("retrieveUserByNameAndPassword", conObj);
comObj.CommandType = CommandType.StoredProcedure;
comObj.Parameters.Add(new SqlParameter("@Username", User.Username));
comObj.Parameters.Add(new SqlParameter("@Password", User.UserPassword));
conObj.Open();
return Convert.ToInt32(comObj.ExecuteScalar());
}
}
}
}
从Login.cshtml中提取我可以发布完整代码
<script>
$("#Login").click(function ()
{
var dataObject = { UserName: $("#UserName").val(), Password: $("#Password").val() };
$.ajax({
url:'@Url.Action("Login","User")',
type:"POST",
data: dataObject,
datatype: "json",
success: function(result)
{
if(result.toString()=="Success")
{
alert(result);
}
else
{
alert(result);
}
},
error: function (result)
{
alert("Error");
}
});
})
</script>
【问题讨论】:
-
你的脚本前是否包含 jquery?
-
你是否为 jquery 添加了
<script>标签,类似于<script src='/scripts/jquery.min.js"></script>?
标签: javascript html