<分区>
我花了大约 10 个小时并阅读了无数帖子试图解决这个问题,但不得不承认失败,所以希望有好心人能帮我理顺。
我正在尝试将数据发送到我的 Controller (GET) 以返回部分 View 。尽管我尝试了各种变化,但 Controller 接收到的模型始终为空。为了使其真正简单,我将模型缩减为一个元素。
我错过了什么? (提前致谢)
型号:
public class TextContentViewModel
{
public string ContentType {get; set;}
}
Controller :
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");
}
});
};