我已经花了大约 10 小时阅读了无数帖子试图弄清楚这一点,但不得不承认失败,所以希望某个善良的灵魂能理顺我。
我正在尝试将数据发送到我的控制器 (GET) 以返回部分视图。尽管我尝试了各种变化,但控制器收到的模型始终为空。为了保持简单,我将模型缩减为一个元素。
我错过了什么?(提前致谢)
模型:
public class TextContentViewModel
{
public string ContentType {get; set;}
}
控制器:
public ActionResult Preview(TextContentViewModel paneContent)
{
return PartialView("_Text");
}
Javascript:
<script type="text/javascript">
$("#previewButton").click(showPreview);
function showPreview() {
content = {
ContentType: $("#ContentTypeID").val(),
}
$.ajax({
url: '@Url.Action("Preview")',
type: 'GET',
contentType: 'application/json',
data: JSON.stringify(content),
success: function (result) {
$('#preview').html(result);
},
error: function (result) {
alert("something went wrong");
}
});
};