2015-04-14 39 views
0

这是我的jQuery代码 ,接下来是我的json函数来处理这个名为InsertMatlabJson的jQuery代码。如何将HTML内容发送到ASP.NET MVC JSON函数?

问题是没有文本进入到.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) 
    { 

}

+0

你想通过发送HTML查询并在函数上接收它作为文本变量? –

+0

是你的问题,在ASP.NET MVC中,你没有收到任何文本参数? – BadFeelingAboutThis

+1

尝试更改:类型:'GET'键入:'POST' –

回答

0

这应该这样做

[AllowHtml] 
public JsonResult InsertMatlabJson(string text) 
{ 

} 
+3

为了让这个答案对别人有用,你应该添加一个关于你的代码是什么以及如何解决问题的简单解释。“做这个”类型的回答并不能帮助任何人改进他们的代码 – scrappedcola

+0

我认为标签“AllowHtml”非常好解释自己... –