2013-10-24 27 views
-1

如何將HTML表格從視圖發送到控制器。 我有表在視圖中,我在網格中顯示我的數據,現在我必須將這個網格數據在HTML文件中發送到controller.i達到這裏我創建了我的表的HTML文件,我必須將此文件發送到控制器。如何從視圖向mvc4中的控制器發送html表格

<HTML> 
<table> 
<tr><TD> 12 <TD></tr> 
</table> 
</HTML> 


var request = $.ajax({ 
       url: '..controllername/actionname?htmlTableValue'+htmlTableValue,//action method url which defined in controller 
       type: 'POST', 
       cache: false, 
       data: JSON.stringify(htmlTableValue), 
       dataType: 'json', 
       contentType: 'application/json; charset=utf-8' 
      }); 


[HttpPost] 
     public ActionResult nameOfTheAction(string htmlTableValue) 
     { 
     } 

達到空值控制器 它失敗 將數據發送到CONTROLER

+2

-1對於很好的問題和很好的解釋,並給出了正確的細節:p,嘿給我更多的細節雅。這不是一個質量問題 –

+0

男人給我回答我更新 – Pankaj

+1

什麼?對不起,再說一遍? –

回答

3
var htmlTableValue = "<HTML> 
<table> 
<tr><TD> 12 <TD></tr> 
</table> 
</HTML>"; 

var request = $.ajax({ 
       url: '',//action method url which defined in controller 
       type: 'POST', 
       cache: false, 
       data: JSON.stringify(htmlTableValue), 
       dataType: 'json', 
       contentType: 'application/json; charset=utf-8' 
      });`enter code here` 
0

試試這個,

在View: -

var htmlTableValue = "<HTML> 
<table> 
<tr><TD> 12 <TD></tr> 
</table> 
</HTML>"; 

var request = $.ajax({ 
       url: '',//action method url which defined in controller 
       type: 'POST', 
       cache: false, 
       data: JSON.stringify(htmlTableValue), 
       dataType: 'json', 
       contentType: 'application/json; charset=utf-8' 
      }); 

在控制器: -

[HttpPost] 
     public ActionResult nameOfTheAction(string htmlTableValue) 
     { 
     } 
+0

man它通過解析器錯誤,爲什麼?我的HTML含量低於上面提到 – Pankaj

+0

我請JSON.stringify() –

+0

VAR htmlTableValue = 「」 + 「

​​12​​
」 + 「」 添加更多; VAR請求= $就({ URL:」 ../ts/Sport",//action方法,該方法在控制器 類型定義的URL: 'POST', 緩存:假, 數據:JSON.stringify( htmlTableValue), dataType:'json', contentType:'application/json; charset = utf-8' }); – Pankaj

1

下面是解決方案。

Ajax調用的 「數據」 部分,如下

從數據更改你:JSON.stringify(htmlTableValue)

變化數據:JSON.stringify({ htmlTableValue: htmlTableValue })

,然後使用相同的控制器功能,因爲它是。然後檢查結果。

它爲我工作,讓我知道任何問題。

相關問題