0
I have an action in my controller that calls a service that does a search using stored procedure and returns a list to me. I made the form in the View to call this Action, only it’s not calling Follow the Codes of Each Process
Search Form
<p> Buscar Pessoa </p>
<!-- Area de Busca -->
@using (Html.BeginForm())
{
@Html.ValidationSummary()
<div class="form-group">
<p> Nome </p>
@Html.TextBox("Nome")
<input type="submit" value="Buscar" />
</div>
}
Controller - Actionresult Search(string name)
[HttpPost]
public ActionResult Buscar(string Nome)
{
PessoaService srv = new PessoaService();
srv.Buscar(ID);
return View("List", srv.Listar());
}
Stored Procedure - in Personal Service
public List<Pessoa> Buscar(string nome)
{
using(var db = new MyContext())
{
var Result = db.Database.SqlQuery<Pessoa>("SP_Busca_Cliente").ToList();
return Result.ToList();
}
}
QUESTION ---- How do I call this action and return the searched person
Looking over the top, I believe that you still need to specify that the http method triggered by the form should be POST, after all your action will only respond to POST requests. https://msdn.microsoft.com/en-us/library/dd460344(v=vs.118). aspx
– G. M4rc14L
Dude, I managed to call, Using this way there, Now I just need to create the Variables of type Sqlparameter to pass as parameter for my Stored Procedure, You have some easier idea to pass?
– Hugo Guedes
More or less what do you want? https://docs.microsoft.com/en-us/ef/core/querying/raw-sql#Passing-Parameters
– G. M4rc14L