function FillProductbyupc(elem) {
var $elem = $(elem),
upcCode = $elem.data('upc');
$.ajax({
url: '/Case/GetData/',
type: "GET",
dataType: "JSON",
data: "upc=" + upcCode,
success: function (data) {
$(".corpitemcode").append(
$elem.find('.corpitemcode').val(data.CorpItemCode));
$(".itemdesc").append(
$elem.find('.itemdesc').val(data.ItemDsc));
},
error: function () {
alert("UPC does not exist");
}
});
}
$(function () {
$('.products').on('blur', '[data-upc]', function (e) {
FillProductbyupc(this);
});
});
继承我的产品
<div class="product">
<p>
<label>Product</label>
@Html.TextBoxFor(x => x.UPC, null, new { @class = "form-control", placeholder = Html.DisplayNameFor(x => x.UPC), data_upc = "5440001504" })
@Html.TextBoxFor(x => x.PLU, null, new { @class = "form-control", placeholder = Html.DisplayNameFor(x => x.PLU) })
@Html.TextBoxFor(x => x.CorpItemCode, null, new { @class = "form-control corpitemcode", placeholder = Html.DisplayNameFor(x => x.CorpItemCode) })
@Html.TextBoxFor(x => x.ItemDsc, null, new { @class = "form-control itemdesc", placeholder = Html.DisplayNameFor(x => x.ItemDsc) })
@Html.TextBoxFor(x => x.LaneNumber, null, new { @class = "form-control", placeholder = Html.DisplayNameFor(x => x.LaneNumber) })
@Html.HiddenFor(x => x.DeleteProduct, new { @class = "mark-for-delete" })
@Html.RemoveLink("Remove", "div.product", "input.mark-for-delete")
</p>
</div>
我的控制器
public JsonResult GetData(string upc, decimal? corpitemcode)
{
if (!string.IsNullOrEmpty(upc))
{
upc = upc.Replace("-", "");
}
CICS data = new CICS();
data = CICSManager.GetbyUPCorCorp(upc, corpitemcode);
return Json(data, JsonRequestBehavior.AllowGet);
}