weixin_33696822 2015-02-16 07:40 采纳率: 0%
浏览 44

将列表从Jquery传递到视图

I want to pass list from jquery ajax to the particular view. In a view user select the type. If they select first type, then it will load two lists and pass to the particular view data. How to do this in Ajax Jquery?

<%:Html.RadioButtonFor(model=> model.Type, 1)%>  Type 1
<%:Html.RadioButtonFor(model=> model.Type, 2)%>  Type 2

$("#Type").change(function () {
  var type = $("#Type");
  if (type == 1) {
    //*****The following things are added from controller. i want to pass the following lists from ajax*******/
    List<SelectListItem> type= new List<SelectListItem>();
    type.Add(new SelectListItem { Text = "one", Value = "14" });
    type.Add(new SelectListItem { Text = "two", Value = "12" });
  }
});

how to do this

  • 写回答

1条回答 默认 最新

  • weixin_33692284 2015-02-16 09:16
    关注

    I'm presuming that you want to submit the form to pass the value to the view?

    If so, in the view with the form elements have the AJAX call:

    <script>
    $(document).ready(function() {
        $("#the-form-id").on("submit", function(e) {
           e.preventDefault();
           $.ajax({
              type: "POST",
              url: "/your-controller-name/your-action-name,
              data: $("#the-form-id").serialize(),
              success: function(data) {
                  //do something with the View that is returned...
              }
           });
        });
    });
    </script>
    

    Then, you;'ll need an action in the controller the AJAX is calling that accepts the "data" being passed from the form. In ASP MVC, this will normally be a corresponding Model.

    Said action will return a View set up however you want it to be. The original AJAX call will receive this so you can utilize it however you want to.

    Hope that helps.

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算