Here’s my situation: i have a dialog form that inserts some data on my database. After everything is validate, the form info is turned to a database object (i’m using linq to sql) and is submitted.
Since i’m doing this using jquery ajax, i have a success function that displays some message to the user (just to inform him that his action was successful), closes my dialog and refresh my main page. And that’s the problem, none of the success actions are occuring due some strange download window that’s showing up, asking me if i want to download my controller action (you’ll se on my code).
Here’s the reducted code:
JQuery Submit Function
//Submete a nova solicitão ao servidor e atualiza a página em caso de sucesso
$("#novaSIForm").submit(function (e) {
e.preventDefault();
$.ajax({
type: "Post",
url: $(this).attr("action"),
cache: false,
data: $(this).serialize(),
success: function (data) {
//Fecha a modal
$("#novaSIModal").dialog("close");
//Após a requisição ter sucesso, atualiza a página
$("#SiContainer").load('@Url.Action("SolicitacoesInternas")');
alert(data.msg);
},
error: function (jqr, errorStatus, errorThrow) {
alert("Erro ocorrido " + errorStatus);
}
});
return false; //Isso faz com o que o form não execute sua ACTION
});
ACTION
public ActionResult SiNovaSI(ChamadoViewModel chVM, string tituloChamado)
{
try
{
CHAMADO ch = new CHAMADO();
ch.InjectFrom(chVM);//Injeta os valores da ViewModel no novo Chamado criado
//Seta outras propriedades que não foram injetadas anteriormente
ch.DATAINICIO = DateTime.Now;
ch.SOLICITANTE = ((USUARIO)Session["UsuarioLogado"]).NOMEREDUZIDO;
ch.STATUS = "SOLICITADO";
ch.VALORDEBITO = ((DEBITO)Session["Debitos"]).VALORPARCELA;
ChamadoManager chMan = new ChamadoManager();
chMan.InsertCHAMADO(ch);//Insere o novo chamado no banco de dados
return Json(new { sucesso = true, msg = "Chamado cadastrado com sucesso" });
}
catch (Exception e)
{
return Json(new { sucesso = false, algo = "Nao foi possível registrar o chamado. Erro: " + e.Message });
}
}
Image

Oh, i forgot to mention that i have included all the necessary jquery scripts. Including some MS Ajax scripts (even though i’m no longer using it).
If this
#novaSIFormwas dynamically generated (maybe after an AJAX call) you might loose your.submithandler if the DOM element is replaced. So you could use the.livemethod. Also make sure that this event subscription happens inside thedocument.readyevent handler (in the case you are using.submitinstead of.live)Also inspect with FireBug the actual AJAX request that is being sent and that there are no javascript errors occurring.