javascript - 在文件夹中插入图像在控制器中显示空值
问题描述
我想在客户端插入图像。图像 URL 插入到网格中,但是当我单击保存按钮时,图像 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>
解决方案
推荐阅读
- node.js - pm2 --watch 每隔 3 秒记录一次,与配置文件无关
- python - Django Inline Admin - 如何覆盖保存行为
- python - Python - 无法解码获取命令输出
- python - Access PostgreSQL hstore keys and values in Python and create new dataframe column for each key
- nao-robot - Choregraphe:如何更改 NAO 的胸部和脚部 LED
- python-3.x - Hi, I'm a beginner in Python, and I would like to know how to get an index number from a list with multiple values in the same index
- php - The "no-ansi" option does not exist
- java - how to allow java telegram bot wait user reply?
- android - background-attachment: fixed; failes on firefox for android
- ios - Compile error when Using the combination of protocol and generic in swift