Click here to Skip to main content
15,893,161 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,
I want to execute a Store Procedure and return the result to the view,after debugging my parameter is passed in SP but it returns nothing and ends up in error.

The model item passed into the dictionary is of type System.Data.Entity.Infrastructure.DbRawSqlQuery`1[SocialAuthentication.Models.User s, but this dictionary requires a model item of type SocialAuthentication.Models.Users.

I have understood that I have declared the model as string the expected output is different how do I fix it.

C#
Model
public class Users
    {   
        public string Name { get; set; }
        public string Email { get; set; }
    }
View
 @using (Html.BeginForm("Contact", "Home"))
    {
    <input id="Text1" type="text" name="txtOne" />
    <input id="Button1" type="submit" value="button" />
    }

   Controller

   [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);
            
        }


Store Procedure

SQL
CREATE procedure usp_searchuser --'Sara Nani'
@UserInput varchar(50)
As
Begin
select Email,Name from tblEmployee where Name = @UserInput
End
Posted

1 solution

You have not inherited the model properly to the view. You have to inherit it like this
@model StartWithMVC.Models.Employee.

For more details you can go through Start With MVC - Push Start For Beginners(Part - 1)[^]
 
Share this answer
 
Comments
Member 9176543 17-Mar-15 13:35pm    
Hi,
I have done that, heres my View.

@model SocialAuthentication.Models.Users
 
@foreach (var item in Model.Name)
{
<ul>
<li>
@item
</li>
</ul>
}

If you will copy past my code debug it then will release that in the Controller action method
var result = db.Database.SqlQuery<users>("usp_searchuser, @UserInput", new SqlParameter("@UserInput", textboxValue));
returns nothing that why no data is passed to the view.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900