我想将一个长字符串从我的视图传递给部分视图并在按钮单击时呈现部分视图。字符串太长,不能作为url的一部分传递,所以必须通过post传递。
单击 Button Details 时,将调用一个 ajax 函数,该函数应将所需的参数传递给局部视图并呈现它。不幸的是,这不起作用,看来我的 ajax 声明中有错误。当我单击详细信息按钮时,没有任何反应,并且调试器跳过了 ajax 声明。
这是我的观点的一部分:
<form class="form-inline" asp-controller="Order" asp-action="Details">
<table class="ComplianceTable" id="ComplianceTable">
<thead>
<tr id='tableHeader'>
<th>Res.</th>
<th>Trend</th>
<th>Portfolio</th>
<th>Level</th>
<th>Code</th>
<th>Description</th>
<th>Rule</th>
<th>Test Type</th>
<th>Limit</th>
<th>Result</th>
<th>(Previous)</th>
<th>Severity</th>
<th>Details</th>
</tr>
</thead>
<tbody>
@foreach (var info in Model.ViolationInfo)
{
<tr>
<td>@info.RuleType</td>
<td></td>
<td>@Model.code</td>
<td></td>
<td></td>
<td></td>
<td>@info.RuleName</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td>
<input type="hidden" id="value1" name="info.Diagnostic">
<button class="btn js-details" type="button" name="Details" data-id="@info.Diagnostic">
Details
</button>
</td>
</tr>
<tr class="info"><td colspan="11">@info.Diagnostic</td></tr>
}
</tbody>
</table>
<div id="getComplianceDetails"></div>
</form>
这是我的部分视图:
@model string
<div id="getComplianceDetails">
<p>Test</p>
<p>
@Model
</p>
</div>
这是我的javascript:
$(document).ready(function () {
$(document).on('click', '.js-details', function (event) {
$("#ComplianceTable tr").removeClass("selected");
$(this).closest('tr').addClass('selected');
var $element = $(event.currentTarget);
var id = $element.data('id');
$.ajax({
url: '@Url.Action("Details", "Order")',
data: {info: id},
type: "POST",
success: function (data) {
$('#getComplianceDetails').html(data);
}
});
});
});
这是我的订单控制器:
public ActionResult Details(string info)
{
return PartialView("~/Views/Shared/complianceDetails.cshtml", info);
}