0

我正在使用summernote,我想将部分数据发布到控制器;这是数据的样子

<p>This is a sample test.&nbsp;</p>

下面是我正在使用的代码

var sHTML = $('#summernote').code();
    $.ajax({
        url: "Home/GetText",
        data: sHTML,
        type: 'POST',
        cache: false,
        contentType: false,
        processData: false,
        success: function (vaildText) {
            // So something
        },
        error: function () {
            alert('error');
            // handle error
        }
    }); 

家庭控制器

[HttpPost]
    [ValidateInput(false)] 
    public ActionResult GetText(string sHTML)
    {
        // doing something

        return Json(vaildText);
    }

但是家庭控制器上的 SHTML 给出了 NULL。我哪里错了?这是将 HTML 数据发布到控制器的正确方法吗?

Arun 请求的堆栈

    Request URL:http://localhost:23680/Home/GetText
Request Method:POST
Status Code:200 OK
Request Headersview source
Accept:*/*
Accept-Encoding:gzip,deflate
Accept-Language:en-US,en;q=0.8
Connection:keep-alive
Content-Length:15
Content-Type:text/plain;charset=UTF-8
Cookie:__AntiXsrfToken=9d34feb94ea546abb4f50eb7251b4e25
Host:localhost:23680
Origin:http://localhost:23680
Referer:http://localhost:23680/
User-Agent:Mozilla/5.0 (Windows NT 6.2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.103 Safari/537.36
X-Requested-With:XMLHttpRequest
**Request Payload**
[object Object]
4

2 回答 2

1

您需要创建一个名为 sHTML 的请求参数并传递值

var sHTML = $('#summernote').code();
$.ajax({
    url: "Home/GetText",
    data: {
        sHTML: sHTML
    },
    type: 'POST',
    cache: false,
    contentType: false,
    processData: false,
    success: function (vaildText) {
        // So something
    },
    error: function () {
        alert('error');
        // handle error
    }
});
于 2014-09-06T03:35:00.500 回答
0

只需尝试删除contentType: false并添加datatypeajax 调用,如图所示:-

var sHTML = $('#summernote').code();
$.ajax({
  url: "Home/GetText",
  data: {
    sHTML: sHTML
  },
  type: 'POST',
  datatype:'JSON'
  cache: false,
  processData: false,
  success: function (vaildText) {
    // So something
  },
  error: function () {
    alert('error');
    // handle error
  }
});
于 2014-09-06T04:45:51.977 回答