我尝试了几种方法让这个元组列表在我的cshtml视图中显示为uploadModel.ErrorsList但是没有运气,这只显示了Errorslist(元组列表int,string,string)对象的类型, ErrorMessages(字符串)确实在屏幕上显示正确的值。以下是我的观点:
@using Custom.Website.Areas.Custom.Models
@model Custom.Website.Areas.Custom.Models.ExcelUploadModel
<style type="text/css">
#ExcelUploadForm {
text-align: center;
}
</style>
<div id="ExcelUploadForm" title="Excel Upload Results">
<h2 id="requireReUpload" style="color:darkred">Please fix the following errors and reupload:</h2>
<h2 id="uploadSuccess" style="color:green">Your Upload was successful. @Model.UploadedRowCount tickets updated.</h2>
<div>Editable fields: Transporter Ticket #,Transporter, Driver, Truck, AFE #, Water Type, Quantity, Operator Job #, Lease.</div>
<div>
<ul id="uploadErrors"></ul>
</div>
<button class="backButton">Back</button>
</div>
<script type="text/javascript">
document.getElementById("requireReUpload").style.display = 'none';
document.getElementById("uploadSuccess").style.display = 'none';
$(document).ready(function () {
$('#uploadErrors').append('<li>@Model.ErrorMessage</li>');
$('#uploadErrors').append('<li>@Model.ErrorsList</li>');
//This function checks if the Error list contains any value.
function excelUploadMessage() {
// If Error List has nothing, display Success
if ($('ul#uploadErrors:not(:has(li)')) {
document.getElementById("uploadSuccess").style.display = 'block';
} // Otherwise, display reupload message
else {
document.getElementById("requireReUpload").style.display = 'block';
}
}
excelUploadMessage();
});
$('.backButton').click(function () {
window.history.back();
});
</script>
答案 0 :(得分:1)
而不是:
$('#uploadErrors').append('<li>@Model.ErrorsList</li>');
创建一个for循环:
@foreach (var tupleErr in Model.ErrorsList){
<text>$('#uploadErrors').append('<li>@tupleErr.Item1 @tupleErr.Item2 @tupleErr.Item3</li>');</text>
}
抱歉没有验证语法;但想法是你需要迭代列表,然后为列表中的每个项添加一个附加jQuery语句。请记住,您可以通过属性访问元组项目&#34; Itemx&#34;