繁体   English   中英

存储过程未在MVC 5中返回值

[英]Stored procedure is not returning values in MVC 5

在调试将参数传递到存储过程后,我想执行存储过程并将结果返回到视图,但是它什么也没有返回,并最终导致错误

传递到字典中的模型项的类型为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

在您的通话中,usp_searchuser之后不应有逗号。 这使其成为非法的SQL查询。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM