Asp.net mvc 5 e jquery
Boa tarde!
Alguém pode me ajudar por favor?
Quero abrir o detalhe do produto que formatei na minha controller, porém quando chamo o método ele abre apenas o método sem o layout da minha Shared, alguém pode me ajudar por favor?
public string ProdutoDestaques(string param )
{
var b = new StringBuilder();
try
{
var uow = new UnitOfWork();
var lista = new List<Produto>();
string[] include = new string[] { };
lista = uow.ProdutoRepositorio
.Listar(i => i.Finalidade == param, include).OrderByDescending(x => x.Referencia).Take(4).ToList();
foreach (var item in lista)
{
var nome = "<span>" + item.Referencia + "</span>";
var url = Url.Action("Detalhe", "Home", new { referencia = item.Referencia });
b.AppendLine("<div class='box_detalhes'>");
b.AppendLine("<div class='box_foto'><a href=''><img src='/Content/images/sgimais.jpg' title='Clique para Ampliar' border='0' alt='Foto do imóvel' /></a></div> ");
b.AppendLine("<div class='desc_box'>");
b.AppendLine("<p> <strong> Referencia: </strong>" + item.Referencia + "</p> ");
b.AppendLine("<p> <strong> " + item.IdTipoImovel + "</strong></p> ");
b.AppendLine("<p> <strong> " + item.Localizacao + "</strong></p> ");
b.AppendLine("<p> <strong> Valor Venda: </strong> <span>" + item.ValorVenda.ToString() + "</span> </p> ");
b.AppendLine("<p> <strong> Valor Locação: </strong> <span>" + item.ValorLocacao.ToString() + "</span> </p> ");
b.AppendLine("<li>");
**Quando clica neste botão, ele executa o controller Detalhe, porém ele mostra só o resultado sem o layout do projeto.**
b.AppendLine("<a href=" + url + ">");
b.AppendLine("Teste </a>");
b.AppendLine("</li>")
b.AppendLine("</div>");
b.AppendLine("</div>");
}
if (lista.Count > 0)
{
return b.ToString();
}
else
return SemMensagens();
}
catch
{
return SemMensagens();
}
}
Função:
Detalhe: function (referencia) {
var url = "/Home/Detalhe";
$.ajax({
url: url,
datatype: "html",
type: "GET",
data: { referencia:referencia },
}).done(function (data) {
$("#Detalhe").html(data);
}).fail(function (jqXHR, exception) {
TratamendodeErro(jqXHR, exception);
});
},
Controller:
public ActionResult Detalhe(int referencia)
{
var b = new StringBuilder();
try
{
var uow = new UnitOfWork();
var lista = new List<Produto>();
string[] include = new string[] { };
lista = uow.ProdutoRepositorio
.Listar(i => i.Referencia == referencia.ToString(), include).ToList();
foreach (var item in lista)
{
var nome = "<span>" + item.Referencia + "</span>";
var descricao = item.Descricao.ToString();
b.AppendLine("<div class='box_detalhes'>");
b.AppendLine("<div class='desc_box'>");
b.AppendLine("<p> <strong> Referencia: </strong>" + item.Referencia + "</p> ");
b.AppendLine("<p> <strong> " + item.IdTipo + "</strong></p> ");
b.AppendLine("</div>");
b.AppendLine("</div>");
}
if (lista.Count > 0)
{
return View(b.ToString());
}
else
return View(SemMensagens());
}
catch
{
return View(SemMensagens());
}
}Discussão (2)
Carregando comentários...