1
Controller Action
public class EstabelecimentoController : ControllerBase
{
[HttpPost]
public ActionResult ImportarEstabelecimentos()
{
var file = Request.Files["inputFileImportarEstabelecimentos"];
return RedirectToAction("Index");
}
}
Excerpt from the HTML input
Importar <input id="inputFileImportarEstabelecimentos" name="inputFileImportarEstabelecimentos" type="file" onchange="ImportarEstabelecimentos()" />
Javascript snippet
<script type="text/javascript">
$(document).ready(function () {
});
function ImportarEstabelecimentos() {
$.ajax({
type: "POST",
url: "/Estabelecimento/ImportarEstabelecimentos",
datatype: "JSON",
contentType: "application/json; charset=utf-8",
data: {},
success: function() { alert('Success'); }
});
}
Ajax is coming to the controller?
– Maycon F. Castro
@Mayconf.Castro, exactly that the problem, Ajax is not giving error, but it does not enter my Controller Action
– Nicola Bogar
url puts url: Urlapplication + "/Establishment/Importestablishments"
– Maycon F. Castro
@Mayconf.Castro, what would this Urlapplication be ?
– Nicola Bogar
can you open the url in the browser? if you are using Chrome, use dev tool (F12) and look at the flap Network to see the call and which answer is returned
– Ricardo Pontual
It’s to get the local url
– Maycon F. Castro
@Mayconf.Castro, very strange as no request works, I tried for other action and nothing, I changed post to get and also nothing..
– Nicola Bogar
Your ajax is being called?
– Maycon F. Castro
The ajax is correct, maybe he’s not being called. Try to put some message in the function to be able to see it in the console, or try to put the event onchange by javascript code.
$("#campo").on("change", function(){})
– Raul Medeiros
puts a
.
here:./Estabelecimento/ImportarEstabelecimentos
– Marconi
Remove the
datatype: "JSON", contentType: "application/json; charset=utf-8",
if you’re not expecting a JSON as an answer.– Sam