【发布时间】:2015-03-16 13:29:07
【问题描述】:
我想执行一个存储过程并将结果返回给视图,调试后我的参数被传递到存储过程中,但它什么也没返回并最终出错
传入字典的模型项的类型为 System.Data.Entity.Infrastructure.DbRawSqlQuery`1[SocialAuthentication.Models.User s,但此字典需要 SocialAuthentication.Models.Users 类型的模型项。
我知道我已经将模型声明为字符串预期的输出不同我该如何修复它。
我的模型
public class Users
{
public string Name { get; set; }
public string Email { get; set; }
}
查看
@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
【问题讨论】:
-
在 SQL Profiler 中监控 SP,看看发生了什么疯狂的事情
标签: c# sql-server-2008 asp.net-mvc-5