1
How to make a post
sending data to a ActionResult
of a Controller
different from the current ? Example:
I have a link called lnkEnviarDados
and I need to post on the page sending the contents of the variables when I click on this link.
@using (Html.BeginForm("Index", "Pessoa", FormMethod.Post))
{
<table class="grid">
<tbody>
<tr>
<td>
<a href="#" class="lnkEnviarDados" name="downloaditem" id="downloaditem2" data-id_Atributo_1="6" data-id_Atributo_2="1" data-id_Atributo_3="2" target="_blank">
<span class="idSpan">Regular</span>
</a>
</td>
</tr>
</tody>
</table>
}
@section Scripts{
<script type="text/javascript">
$(document).ready(function () {
$(document).on('click', '.lnkEnviarDados', function (e) {
e.preventDefault();
var _Atributo_1 = $(this).attr("data-Atributo_1");
var _Atributo_2 = $(this).attr("data-Atributo_2");
var _Atributo_3 = $(this).attr("data-Atributo_3");
//Fazer um post deste controller para enviar os dados acima
//para um outro Controller chamado "BaixarConta"
});
}
}
CONTROLLER Baixarconta
[HttpPost]
public ActionResult BaixarConta(int _Atributo_3, int _Atributo_2, int _Atributo_3)
{
}
Your Actionresult has the same name as your controller?
– Tiago S
@James S does not have the same name, but I saw in his reply how to proceed, I will implement and then post here the result. Thank you!.
– hard123
@Tiago S sending the data works perfectly, but the
ActionResult
returns aFileStreamResult
that does not work example: Return new Filestreamresult(pdfStream, "application/pdf"); the fact of posting the page in this way influences the non-working of Return ?– hard123
Yes, totally, but that’s outside the scope of your question. Mark the answer as accepted and if possible an up vote :) and create a new question, for example how to download file via $.ajax()
– Tiago S