iT邦幫忙

0

ASP.NET MVC 從View 傳值給Controller

網頁會先點擊圖上的藍點,會跳出類似對話框的視窗,如下圖所示
https://ithelp.ithome.com.tw/upload/images/20180526/20110063vzRzzAvMVO.jpg
希望能把選擇的選項傳值給Controller,按下一步時印出選擇的結果
目前遇到的問題是 : 按下一步時不會有任何反應
麻煩大家指導一下問題所在~謝謝~

以下為view 的程式碼
https://ithelp.ithome.com.tw/upload/images/20180526/20110063AZw1tMAGAn.jpg
https://ithelp.ithome.com.tw/upload/images/20180526/20110063Q0UvTqDOwk.jpg
https://ithelp.ithome.com.tw/upload/images/20180526/201100637IS8v9ZpKJ.jpg

Controller的程式碼

[HttpPost]
 public ActionResult SectionB(int B1)
 {
      return this.Content(B1.ToString(), "application/json");
 }
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

2 個回答

0
暐翰
iT邦大師 1 級 ‧ 2018-05-26 18:04:55
最佳解答

按下一步時印出選擇的結果

controller沒有看到列印的程式邏輯,只有回傳字串頁面而已
請問列印邏輯寫在前端還是後端呢?

假如是懷疑沒有正確傳到對應連結跟參數
可以用chrome F12工具 -> network查看

wjing iT邦新手 1 級 ‧ 2018-05-26 21:36:33 檢舉

謝謝!這個方法讓我找到問題所在

0
小魚
iT邦大師 1 級 ‧ 2018-05-26 21:07:19

你有在後端下中斷點,
確定後端確實有收到資料嗎?
另外你試著用string接收看看,
不要用int來接收。

wjing iT邦新手 1 級 ‧ 2018-05-26 21:37:05 檢舉

謝謝~我下中斷點之後有找到問題所在了~

我要發表回答

立即登入回答