1
I have a Model
called: Cliente_man
that represents the customer register.
But this Model
, has a lot of information, and to the screen that I am developing not ah need of all, so I would like to move to the View
one Partial Model
only with the data I need to use.
It follows below part of the code receiving the Model
complete(Cliente_Man
)
Controller
:
[ValidateInput(false)]
public ActionResult DetailTabControl()
{
if (Session["cod_cli"] != null)
{
int codCliente = Convert.ToInt32(TempData["codCliente"]);
Cliente_man model = db.Cliente_man.Find(codCliente);
return PartialView("~/Views/Cliente_man/_DetailTabControl.cshtml", model);
}
else
{
return RedirectToAction("Login", "Account");
}
}
View
:
@model OneeWeb_v3.Models.Crm.Cliente_man
<h3>
@Html.DisplayFor(model => model.razao_social).ToHtmlString()
</h3>
So I created a new Model
called: Cliente_manDetalhes
, which contains only the data I need.
I changed in the View
:
@model OneeWeb_v3.Models.Crm.Cliente_manDetalhes
<h3>
@Html.DisplayFor(model => model.razao_social).ToHtmlString()
</h3>
And in the Controller
:
[ValidateInput(false)]
public ActionResult DetailTabControl()
{
if (Session["cod_cli"] != null)
{
int codCliente = Convert.ToInt32(TempData["codCliente"]);
//Cliente_man model = db.Cliente_man.Find(codCliente);
Cliente_manDetalhes mode = from s in db.Cliente_man
where s.id_cliente == codCliente
select new
{
id_cliente = s.id_cliente,
nome_fantasia = s.nome_fantasia,
Perfil = s.Perfil,
n_doc = s.n_doc,
cidade = s.cidade,
siglaEstado = s.siglaEstado
});
return PartialView("~/Views/Cliente_man/_DetailTabControl.cshtml", model);
}
else
{
return RedirectToAction("Login", "Account");
}
}
But how do I retrieve information from Model
Cliente_Man
? To the above code returns the error:
Cannot implicity convert type 'System.Linq.IQueryable<<anonymous type:int id_cliente, string nome_fantasia, string Perfil, string n_doc, string cidade, string siglaEstado>>' to 'OneeWeb_v3.Models.Crm.Cliente_manDetalhes'. An explicit conversion exists
this cliente_mandetalhes 'and the same as Cliente_man ? your query returns the values for this module correctly? if yes just put (this Client) in front of the query
– HudsonPH
Thomas, please always add error messages as text and not as images. In addition to making it easier to read and improve the indexing of the question, it prevents people with external domain blocks from being able to read the entire post.
– Jéf Bueno