I am calling data on text field (Search_Prdno) event change to populate dropdown list and text field, now i want to insert multiple rows into html table using json and insert into database from text field and DropDownList.
<div class="row">
<div style="display: inline-block;">
<div>
@Html.LabelFor(model => model.Prdno, "Barcode", htmlAttributes: new { @class = "control-label col-md-4" })
@Html.EditorFor(model => model.Prdno, new { htmlAttributes = new { @class = "form-control col-md-10", @id = "Search_Prdno" } })
@Html.ValidationMessageFor(model => model.Prdno, "", new { @class = "text-danger" })
</div>
</div>
<div style="display: inline-block;">
<div>
@Html.LabelFor(model => model.Codeitem, "Select Item", htmlAttributes: new { @class = "control-label col-md-3" })
@Html.DropDownList("codeitemId", (SelectList)ViewBag.Codeitem, "Select", htmlAttributes: new { @class = "form-control", @id = "select2-3" })
@Html.ValidationMessageFor(model => model.Codeitem, "", new { @class = "text-danger" })
</div>
</div>
<div style="display: inline-block;">
<div>
@Html.LabelFor(model => model.Bale_QTY, "Bale_QTY", htmlAttributes: new { @class = "control-label col-md-4" })
@Html.EditorFor(model => model.Bale_QTY, new { htmlAttributes = new { @class = "form-control col-md-10", @id = "Bale_Qty", @Value = "1" } })
@Html.ValidationMessageFor(model => model.Bale_QTY, "", new { @class = "text-danger" })
</div>
</div>
<div style="display: inline-block;">
<div>
@Html.LabelFor(model => model.Prdno, "BarCode", htmlAttributes: new { @class = "control-label col-md-4" })
@Html.EditorFor(model => model.Prdno, new { htmlAttributes = new { @class = "form-control col-md-10", @id = "Barcode_Bale" } })
@Html.ValidationMessageFor(model => model.Prdno, "", new { @class = "text-danger" })
</div>
</div>
<div style="display: inline-block;">
@Html.LabelFor(model => model.OrderNo, "OrderNo", htmlAttributes: new { @class = "control-label col-md-2", @id = "P_OrderNo" })
@Html.HiddenFor(Model => Model.OrderNo)
</div><div style="display: inline-block;">
@Html.LabelFor(model => model.weight, "Weight", htmlAttributes: new { @class = "control-label col-md-2", @id = "I_Weigth" })
@Html.HiddenFor(Model => Model.weight)
</div>
</div>
function GetBarcodeSB(prdno) {
$.ajax({
async: true,
type: 'GET',
dataType: 'JSON',
contentType: 'application/json; charset=utf-8',
url: '/OrderPack/GetBarcodeSB',
data: { prdno: prdno },
success: function (data) {
$('#select2-3').empty();
$(data).each(function (index, item) {
$('#select2-3').append($('<option/>', { value: item.Value, text: item.Text }));
})
},
error: function () {
alert("There is some problem to get.");
$("#P_Prdno").empty();
$("#P_OrderNo").empty();
$("#I_Weigth").empty();
}
});
}
function GetBarcodeweight(prdno) {
$.ajax({
async: true,
type: 'GET',
dataType: 'JSON',
url: '/OrderPack/GetBarcodeweight',
data: { prdno: prdno },
success: function (data) {
console.log(data);
//populate the didden field
$("#Prdno").val(data.Prdno);
//populate the label
$("#Barcode_Bale").val(data.Prdno);
//populate the didden field
$("#OrderNo").val(data.OrderNo);
//populate the Orderno
$("#P_OrderNo").text(data.OrderNo);
//populate the didden field
$("#weight").val(data.weight);
//populate the label
$("#I_Weigth").text(data.weight);
//console.log($("#select2-1").val());
var orderNo1 = $('#P_OrderNo').html();
var orderNo2 = $('#Orderno-label-5').html();
if (orderNo1 == orderNo2) {
alert('same order');
}
else {
alert('Not same order');
}
},
//error: function () {
// //alert("There is some problem to get.");
//}
});
}
[HttpGet]
public JsonResult GetBarcodeSB(int prdno)
{
int? Codeitem = DB.Probales.First(a => a.Prdno == prdno).Codeitem;
var STATUS_LIST = (from s in DB.ItemMasterFiles
where s.CodeItem == Codeitem
select
new SelectListItem()
{
Text = s.Descriptionitem,
Value = s.CodeItem.ToString(),
}) . ToList();
return Json(STATUS_LIST, JsonRequestBehavior.AllowGet);
}
[HttpGet]
public JsonResult GetBarcodeweight(int prdno)
{
var query = (from p in DB.Probales.Where(p => p.Prdno == prdno)
join i in DB.ItemMasterFiles on p.Codeitem equals i.CodeItem
select new { ItemMasterFile = i, Probale = p } ).ToList();
var user = query.FirstOrDefault();
var model = new OrderVm()
{
Prdno = user.Probale.Prdno,
OrderNo =user.Probale.OrderNo,
weight=user.ItemMasterFile.weight
};
return Json(model, JsonRequestBehavior.AllowGet);
}
public class OrderVm
{
[Display(Name = "Select Order")]
public int? OrderNo { get; set; }
public int? SOrderNo { get; set; }
public int? Codeitem { get; set; }
[Display(Name = "Input Barcode")]
public int? Prdno { get; set; }
public int? orderqty { get; set; }
public int? prdqty { get; set; }
public int? packQty { get; set; }
public int? Bale_QTY { get; set; }
public int? weight { get; set; }
public Probale smallbale { get; set; }
public ItemMasterFile Itemasterfile { get; set; }
}