C# 存储过程在MVC 5中不返回值
我想执行一个存储过程,并在调试后将结果返回给视图。我的参数被传递到存储过程中,但它什么也不返回,结果是错误的 传递到字典中的模型项的类型为System.Data.Entity.Infrastructure.DbRawSqlQuery`1[SocialAuthentication.Models.Users,但此字典需要SocialAuthentication.Models.Users类型的模型项 我知道我已经将模型声明为字符串,但预期的输出是不同的,我如何修复它 我的模型C# 存储过程在MVC 5中不返回值,c#,sql-server-2008,asp.net-mvc-5,C#,Sql Server 2008,Asp.net Mvc 5,我想执行一个存储过程,并在调试后将结果返回给视图。我的参数被传递到存储过程中,但它什么也不返回,结果是错误的 传递到字典中的模型项的类型为System.Data.Entity.Infrastructure.DbRawSqlQuery`1[SocialAuthentication.Models.Users,但此字典需要SocialAuthentication.Models.Users类型的模型项 我知道我已经将模型声明为字符串,但预期的输出是不同的,我如何修复它 我的模型 public class
public class Users
{
public string Name { get; set; }
public string Email { get; set; }
}
看法
在您的呼叫中,usp\u searchuser后面不应该有逗号。这使其成为非法的SQL查询。在SQL Profiler中监视SP,查看发生了什么疯狂现象检查以下内容:
@using (Html.BeginForm("Contact", "Home"))
{
<input id="Text1" type="text" name="txtOne" />
<input id="Button1" type="submit" value="button" />
}
[HttpPost]
public ActionResult Contact()
{
string textboxValue = Request.Form["txtOne"];
var result = db.Database.SqlQuery<Users>("usp_searchuser, @UserInput", new SqlParameter("@UserInput", textboxValue));
return View(result);
}
CREATE procedure usp_searchuser --'Sara Nani'
@UserInput varchar(50)
As
Begin
select
Email, Name
from
tblEmployee
where
Name = @UserInput
End