I have this view and this works fine
as you see I have added a section (required:false) on _layout and until now there is not problem,
@model final2.Models.ObjetosUnidos.HelperVenta
@{
ViewBag.Title = "Index";
}
@*
<>
*@
@section JavaScript
{
<script type="text/javascript">
$(document).ready(
function () {
var $loading = $('#cargando').hide();
$(document)
.ajaxStart(function () {
$loading.show();
})
.ajaxStop(function () {
$loading.hide();
})
$("#btnselectcliente").click(
function () {
$("#diviniciarventa").hide();
$.when(
$.ajax({
type: "post",
dataType: "html",
url: '@Url.Action("mostrarcuerpo", "venta")',
data: { idcliente: $("#selectcliente").val() }
})
).then(
function (data) {
$("#divcuerpo").html(data);
}, function (error) { alert(error.responseText); }
);
}
);
$(this).on("click", "#btnbuscar", function (e) {
/// Do some stuff ...
var idventa1 = $("#idventa").val();
$.ajax({
type: "post",
dataType: "html",
url: '@Url.Action("buscarproducto", "venta")',
data: { texto: $("#txtbuscar").val(), idventa: idventa1 },
success: function (data) {
$("#divtableproductos").html(data);
},
error: function (error) { alert(error.error); }
});
});
var productoid = 0;
var cantidad = 0.0;
var precio = 0.0;
var iva = 0.0;
var nombre = "";
var codigo = "";
var ventaid = "";
var cantidadelegida = 0.0;
$(this).on(
{
click: function () {
productoid = parseInt(this.cells["productoid"].textContent);
cantidad = parseFloat(this.cells["cantidad"].textContent);
precio = parseFloat(this.cells["precio"].textContent);
iva = parseFloat(this.cells["iva"].textContent);
nombre = (this.cells["nombre"].textContent);
codigo = (this.cells["codigo"].textContent);
ventaid = $("#idventa").val();
$("#txtnombre").val(nombre);
$("#txtcodigo").val(codigo);
}
}, "#tableproductos tbody tr");
var colordefault = "";
$(this).on({
mouseenter: function () {
//stuff to do on mouse enter
colordefault = $(this).css("background-color");
$(this).css("background-color", "#ff0");
},
mouseleave: function () {
$(this).css("background-color", colordefault);
}
}, "#tableproductos tbody tr");
$(this).on(
{
click: function () {
cantidadelegida = $("#txtcantidad").val();
if (cantidadelegida < 0 || cantidadelegida > cantidad) {
alert("Cantidad debe estar entre 0 y " + cantidad);
return;
}
texto = $("#txtbuscar").val();
actualizaprodydetalle(productoid, cantidadelegida, ventaid, texto);
}
}, "#btnagregar");
function actualizaprodydetalle(_productoid, _cantidadelegida, _ventaid, _texto) {
$.when(
$.ajax({
async: false,
type: "post",
dataType: "html",
url: '@Url.Action("muestradetalle", "venta")',
data: { productoid: _productoid, cantidad: _cantidadelegida, ventaid: _ventaid }
}),
$.ajax({
async: false,
type: "post",
dataType: "html",
url: '@Url.Action("buscarproducto", "venta")',
data: { texto: _texto, idventa: ventaid }
})
).then(
function (data1, data2) {
$("#divdetalle").html(data1);
$("#divtableproductos").html(data2);
}
);
}
iddetalle = 0;
$(this).on(
{
mouseover: function () {
iddetalle = parseInt(this.cells["iddetalle"].textContent);
}
}, "#tbldetalle tbody tr");
$(this).on(
{
click: function () {
texto = $("#txtbuscar").val();
try {
$.ajax({
type: "post",
dataType: "html",
url: '@Url.Action("actualizadetalle", "venta")',
data: {
iddetalle: iddetalle,
texto: texto
},
success: function (data) {
$("#divmodal").html(data);
},
error: function (dat) {
alert(dat.responseText);
alert(dat.statusText);
}
});
}
catch (ex) {
alert(ex.message);
}
}
}, "#btnmodificar");
$(this).on(
{
click: function () {
var productoid5 = $("#adproductoid").val();
var ventaid5 = $("#idventa").val();
var texto5 = $("#adtexto").val();
if (parseFloat($("#txtnuevacantidad").val()) < 0 || parseFloat($("#txtnuevacantidad").val()) > (parseFloat($("#addisponible").val()) + parseFloat($("#adcantidadactual").val()))) {
alert("Cantidad debe estar entre 0 y " + (parseFloat($("#addisponible").val()) + parseFloat($("#adcantidadactual").val())));
return;
}
var cantidad5 = parseFloat($("#txtnuevacantidad").val()) - parseFloat($("#adcantidadactual").val());
actualizaprodydetalle(productoid5, cantidad5, ventaid5, texto5);
$('#divmodal').html("");
}
}, "#btnnuevacantidad");
$(this).on(
{
click: function () {
var ventaid5 = $("#idventa").val();
try {
$.ajax({
type: "post",
dataType: "html",
url: '@Url.Action("finalizarventa", "venta")',
data: {
ventaid: ventaid5
},
success: function (data) {
$("#divmodal").html(data);
},
error: function (dat) {
alert(dat.responseText);
alert(dat.statusText);
}
});
}
catch (ex) {
alert(ex.message);
}
}
}, "#btnfinalizarvta");
cambiofinal = 0;
$(this).on(
{
keypress: function (e) {
try {
if (e.which == 13) {//Enter key pressed
total = parseFloat($(this).val());
total = total.toFixed(2);
cobrar = parseFloat($("#fvprecio").val());
cobrar = cobrar.toFixed(2);
cambio = (total - cobrar);
cambio = cambio.toFixed(2);
cambiofinal = cambio;
$("#txtcambio").val(cambio);
}
}
catch (ex) {
alert("Solo números flotantos por favór " + ex.message);
return false;
}
}
}, "#txtentrega");
$(this).on(
{
click: function (e) {
$('#divmodal').html("");
}
}, "#fvcerrar");
$(this).on(
{
click: function (e) {
if (cambiofinal < 0) {
alert("Dinero Insuficiente");
return;
}
$('#divmodal').html("");
var ventaid5 = $("#idventa").val();
//ventafinalizada
$.ajax(
{
type: "post",
dataType: "text",
url: '@Url.Action("ventafinalizada", "venta")',
data: { ventaid: ventaid5 },
async: false,
success: function (response) {
alert(response);
window.close();
},
error: function (data) { alert("Ocurrio un errorxx"); }
}
);
}
}, "#fvfinalizarventa");
//$("#buscar").keypress(function (e) {
// if (e.which == 13) {//Enter key pressed
// //$("#btnaceptar").click();//Trigger search button click event
// alert("buscar enter")
// buscar();
// }
//});
});
</script>
}
<div id="cargando">
<img src="~/Images/cargandoajax.gif" />
</div> ...
I know to add the Javascript code in a file is a good practic, then I copy
$(document).ready(
function () {...}
in a file but it does not work
@section JavaScript
{
<script type="text/javascript" src="~/Scripts/scriptventa.js"></script>
}
what am i doing wrong?
I tried doing it too
<script type="text/javascript" src="~/Scripts/scriptventa.js"></script> (not using @section) but it does not work
Aucun commentaire:
Enregistrer un commentaire