我有一个Ajax请求,在我的控制器中构建一个表。我试图在控制器中使用@Html.DropDownListFor
的razor @Html Helpers创建一个下拉列表,然后将其返回到我的视图中。该视图将@Html.DropDownListFor
呈现为原始语法。当它在控制器中构建然后传递给我的视图时,我似乎完全失去了剃刀的范围。
有没有办法构建/构建razor语法服务器端并让它在视图中成功呈现?
控制器
public ActionResult Index(string siteSelected, string pcmSelected, string busGrpSelected, string monthSelected, string ssoSelected){
var associateResults = _appResult.TOSAdjustmentResult(siteSelected, busGrpSelected, pcmSelected, b.getMonth(monthSelected, true));
foreach (var item in associateAdjusmentResults.view_tos_with_adjustment_final)
{
t1 += "<td>" + item.DIRECTION + "</td>";
t1 += "<td>" + item.CALLS + "</td>";
t1 += "<td>" + item.TALK + "</td>";
t1 += "<td>" + item.HOLD + "</td>";
t1 += "<td>@Html.DropDownListFor(model => model.site, new SelectList(Model.site), '--Site--', new { @id = 'siteId' })</td>";
t1 += "</tr>";
}
return Content(t1);
}
查看
<table class="table-condensed table-hover table-responsive table-bordered two small header" id="adjustmentTable">
<tr>
<td>
Direction
</td>
<td>
Calls
</td>
<td>
Talk
</td>
<td>
Hold
</td>
<td>
DropDownList
</td>
</tr>
</table>
的Jquery / AJAX
$(".clickableRow").on("click", ".clickableRow", function () {
//Getting SSO from search table
var sso = this.cells[1];
$("#adjustmentTable").find("tr:gt(0)").remove();
$.ajax({
url: "/TOSAdjustment/Index",
type: "POST",
data: {
ssoSelected: $(sso).text(),
monthSelected: $('input[name=monthOptions]:checked').val()
}
})
.done(function (res) {
$("#msg").html("Response from search received");
$("#adjustmentTable").append(res);
}).fail(function (x, a, e) {
alert(e);
});
});
表格结果