title: How To Show StoredProcedure Result in MVC View
body: <p>I am unable to fetch storedprocedure result from db and show in view . In DB Storedprocedure is working fine </p>
  
  <p><strong>My StoredProcedure In MsSQL</strong></p>
  
  <pre><code>ALTER PROCEDURE [dbo].[Search]
      (
      @param1 varchar(max), 
      @param2 varchar(max),
      @param3 varchar(max),
      @param4 varchar(max)
      )
  AS
  BEGIN
  select BusinessLogo,BusinessTitle,Details,ProfileUrl,Location,Country from ClientBusinesses where location like '%'+@param1+'%' and location like '%'+@param2+'%'
   and location like '%'+@param3+'%' and location like '%'+@param4+'%'
  END
  </code></pre>
  
  <p><strong>Controller Code Where I am Executing StoredProcedure</strong></p>
  
  <p>I tried Using Following Code But Facing But Can't See Data in ViewBag It gives Error on Foreach loop on ViewBag that column BusinessLogo does not exist but you can see in sp i am fetching BusinessLogo and similar error for other columns also</p>
  
  <pre><code>ViewBag listdata = db.Search(Country, state, city, str);
  </code></pre>
  
  <p>I also tried code below - </p>
  
  <pre><code> List&lt;ClientBusiness&gt; listd=new List&lt;ClientBusiness&gt;();
   listd=db.Search(Country, state, city, str);
  </code></pre>
  
  <p>But it gives error </p>
  
  <pre><code>Error   2   Cannot implicitly convert type 'System.Data.Entity.Core.Objects.ObjectResult&lt;string&gt;' to 'System.Collections.Generic.List&lt;PromoteMyName.ClientBusiness&gt;'    F:\Desktop DATA\Desktop 23 Feb\PromoteMyName\PromoteMyName\Controllers\HomeController.cs    135 23  PromoteMyName
  </code></pre>
  
  <p><strong>In View I am Using Simple Code Below</strong></p>
  
  <pre><code>@foreach(var item in  ViewBag.listdata)
     {
  }
  </code></pre>
  
  <p>Is this possible to pass  data fetched from sp to view via viewbag ?</p>