1
A jquery function will call a modal screen when changing a Dropdownlist. When I make the change, the value of id
should be sent to Action there is then made a calculation and the result is sent to the jquery. Soon that jquery, takes this result and checks, if the value is 0(zero), then the Modal is displayed, otherwise no. I’m trying to mount this jquery, just the beginning of it, but I don’t know how to pick up the call back of function jquery. All in this function are attempts, they are not complete or correct, I imagine.
$(document).ready(function () {
$('#faturarParaDrop').change(function () {
var $div = $('#modalPartial');
$.ajax({
url: '',
type: 'GET',
success: function (dados) {
alert(dados);
$div.html(dados);
alert(2);
},
error: function (erro) {
}
})
});
});
That’s the Controller which will calculate and receive the jquery parameter. I have not yet put the parameter, because I have doubts about how to do it and the var qry to return 0 or another value and jquery if 0 display is not following the flow.
[HttpGet]
public ActionResult FaturarPara(int id)
{
ViewBag.Order = _orderService.GetById(CurrentReseller.Id, CurrentCustomer.CustomerGuid, id);
var options = _orderService.ListarFaturarParaOptions(CurrentReseller.Id, CurrentCustomer.CustomerGuid, id);
var customer = _customerService.ListCustomerByReseller(CurrentReseller.Id);
var qry = customer.Where(x => x.Type == CustomerTypeRequest.Customer);
return View(options);
}
How I pass and take value in one jquery for call back and controller(action)?
EDIT1
By changing jquery to this one, I get the dropdownlist ID. With this parameter, I can then query. Now, as a return to jquery the value returned from the query, for me to call or not the modal?
$(document).ready(function () {
$('#faturarParaDrop').change(function () {
var $div = $('#modalPartial'); //exibir a modal
var $idcustomer = $(this).val(); //valor do id da dropdownlist
$.ajax({
url: '',
dataType: 'json',
contentType: "application/json; charset=utf-8",
type: 'POST',
data: JSON.stringify({ idcustomer: $idcustomer }),
success: function (dados) {
alert(dados);
$div.html(dados);
alert(2);
},
error: function (erro) {
}
})
});
});
Controller Action looks like this
[HttpPost]
public ActionResult FaturarPara(OrderFaturarParaOptions model, int idcustomer)
{
var order = _orderService.SalvarFaturarPara(CurrentReseller.Id, CurrentCustomer.CustomerGuid, model);
var customer = _customerService.ListCustomerByReseller(CurrentReseller.Id);
var qry = customer.Where(x => x.Type == CustomerTypeRequest.Customer && x.CustomerId == model.CustomerId)
.Select(x => x.CompanyName ).FirstOrDefault();
return RedirectToAction("GetOrderDetail", "SearchOrders", new { id = model.OrderId });
}
And what of this action you want to return to the view, to
options
?– Leandro Angelo
@Leandroangelo, I would like to return only one value, which would be qry, after the query is fully assembled, type qry = 0 or qry = 3.45 and so on. This value is going to shoot or not the Modal
– pnet
Based on Leandro’s answer, I think the post in jquery, for what I want, didn’t see it working. I switched to GET, but the parameter doesn’t arrive in Action
– pnet
The whole point is that I route jquery by passing,controller/action_name and nothing happens. If I try to get another Action inside my controller, it doesn’t roll, it doesn’t work, only that jquery is inside the View XPTO. It has influence?
– pnet