我想在客户端插入图像。图像URL插入网格中,但是当我单击“保存”按钮时,图像URL不会传递给控制器并显示结果为空值。但是图像URL显示在网格图像列中,但不会传递给控制器。
第二个问题:当我上传图片时,仅显示要显示图片视图的图片的网址,您能否告诉我如何在此代码中显示图片。
c#
[HttpPost]
public ActionResult mQuotationInsert(int Qt_ID, string EnteryDate, string Purpose, Quotation[] Quot, string AddNew)
{
string result = "Error! Order Is Not Complete!";
try
{
objQuotation.QuotationInsert(Qt_ID, EnteryDate, Purpose, Quot, AddNew);
ModelState.Clear();
result = "Quotation Inserted Successfully!";
return Json(result, JsonRequestBehavior.AllowGet);
}
catch (Exception)
{
throw;
}
}
JavaScript
// Add Multiple Record
$("#addToList").click(function (e) {
e.preventDefault();
if ($.trim($("#PartyName").val()) == "" || $.trim($("#txtfile").val()) == "") return;
var Srno = document.getElementById("detailsTable").rows.length,
PartyName = $("#PartyName").val(),
image = $("#txtfile").val(),
IsMature = $("#chkNIsMature").is(":checked"),
detailsTableBody = $("#detailsTable tbody");
var Qt = '<tr><td>' + Srno + '</td><td>' + PartyName + '</td><td>' + image + '</td><td>' + IsMature+ '</td><td> <a data-itemId="0" href="#" class="deleteItem">Remove</a></td></tr>';
detailsTableBody.append(Qt);
clearItem();
});
$("#saveQuotation").click(function (e) {
e.preventDefault();
var QuotationArr = [];
QuotationArr.length = 0;
$.each($("#detailsTable tbody tr"), function () {
QuotationArr.push({
Srno: $(this).find('td:eq(0)').html(),
PartyName: $(this).find('td:eq(1)').html(),
image: $(this).find('td:eq(2)').html(),
IsMature: $(this).find('td:eq(3)').html()
});
});
var data = JSON.stringify({
Qt_ID: parseInt($("#txtQtID").val()),
EnteryDate: $("#txtNEnteryDate").val(),
Purpose: $("#txtNPurpose").val(),
Quot: QuotationArr,
AddNew: $("#AddNew").val()
});
$.when(saveQuotation(data)).then(function (response) {
console.log(response);
}).fail(function (err) {
console.log(err);
});
});
HTML
<!--Detail-->
<h5 style="margin-top:10px;color:#ff6347">Quotation Details</h5>
<hr />
<div>
<div class="form-row">
<div class="col">
<div class="md-form">
<label for="lblPartyName">Party Name</label>
<input type="text" id="PartyName" name="PartyName" placeholder="Party Name" class="form-control" ,Required=true />
</div>
</div>
<div class="col">
<form class="md-form">
<label for="lblPartyName">Image File</label>
<div class="file-field">
<div class="btn btn-outline-success btn-sm float-left">
<input type="file" id="txtfile" name="file">
</div>
<div class="file-path-wrapper" hidden>
<input class="file-path validate" type="text" placeholder="Upload your file">
</div>
</div>
</form>
</div>
<div class="col">
<!-- IsMature-->
<div class="custom-control custom-checkbox custom-control-inline">
@Html.CheckBoxFor(m => m.IsMature, new { @class = "custom-control-input", @id = "chkNIsMature" })
<label class="custom-control-label" for="chkNIsMature">Mature</label>
</div>
</div>
<div class="col-md-2 col-lg-offset-4">
<a id="addToList" class="btn btn-primary">Add To List</a>
</div>
</div>
<table id="detailsTable" class="table">
<thead style="background-color:#007bff; color:white">
<tr>
<th style="width:2%">SrNo.</th>
<th style="width:40%">Party Name</th>
<th style="width:30%">Image</th>
<th style="width:30%">Mature</th>
<th style="width:10%"></th>
</tr>
</thead>
<tbody></tbody>
</table>
</div>