【问题标题】:How to send HTML content to ASP.NET MVC JSON function?如何将 HTML 内容发送到 ASP.NET MVC JSON 函数?
【发布时间】:2015-04-14 17:02:40
【问题描述】:

这是我的 jQuery 代码 接下来是我的 json 函数来处理这个名为 InsertMatlabJson 的 jquery 代码。

问题是 .NET json 函数中没有文本。 . .

    function insert() {
       var url = '<%=Url.Content("~/") %>' + "Matlab/InsertMatlabJson";
       var text = document.getElementById('MainContent_FreeTextBox1').value
   $.ajax({
            url: url,
            type: 'GET',
            data: {  text: text},
            contentType: 'application/json; charset=utf-8',
            success: function (response) {
                //your success code
                alert("opk");
            },
            error: function () {
                //your error code
                alert("no");
            }
        }); 
}
这是我在 ASP.NET MVC 中的 Json 函数
 public JsonResult InsertMatlabJson(string text)
    {

}

【问题讨论】:

  • 你想通过查询发送html并作为文本变量在函数上接收吗?
  • 您的问题是,在 ASP.NET MVC 中您没有收到 text 参数中的任何内容吗?
  • 尝试将:type: 'GET' 改为 type: 'POST'
  • 是的,我收到简单的文本(嗨)!;但我不收到(

    );
  • 我朋友的任何方式都不起作用:-(

标签: javascript c# jquery json asp.net-mvc


【解决方案1】:

应该这样做

[AllowHtml]
public JsonResult InsertMatlabJson(string text)
{

}

【讨论】:

  • 为了让这个答案对其他人有用,您应该添加一个简短的说明,说明您的代码的作用以及它如何解决问题。 “这样做”类型的答案并不能帮助任何人改进他们的代码。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-08
  • 2011-07-03
  • 1970-01-01
  • 2023-03-11
相关资源
最近更新 更多