【问题标题】:View is not affecting on button click视图不影响按钮单击
【发布时间】:2015-08-24 05:37:53
【问题描述】:

    $("#btntest").click(function () {
            alert('Called btn test');
            var FromDate = $("#FromDate").val();
            var ToDate = $("#ToDate").val();
            var UserId = $("#ddlUserName")[0].value;
            debugger;
            $.ajax({
                url: '<%:Url.Action("Grid1","GridView") %>',
                  data: '{"uid":"' + UserId + '","fdate": "' + FromDate + '","tdate":"' + ToDate + '"}',
                  type: "POST",
                  contentType: "application/json; charset=utf-8",
                  success: function (data) {
                      alert('Success');
                      alert(data);
                      window.open("../GridView/Grid1");
                  }
              });

        });

在按钮上单击 GridView 操作必须使用其各自的视图(Grid1)调用

public ActionResult Grid1(string uid, string fdate, string tdate) {

        List<modeldata> list = new List<modeldata>();
        DataTable ds1 = new DataTable();

        SqlCommand cmd = new SqlCommand("spGettLeadReport", con);
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.Add("@UserID", uid);
        cmd.Parameters.Add("@FromDate", fdate);
        cmd.Parameters.Add("@ToDate", tdate);



        SqlDataAdapter da = new SqlDataAdapter(cmd);
        da.Fill(ds1);
        foreach (DataRow dr in ds1.Rows)
        {
            list.Add(new modeldata
            {
                LeadName = dr["LeadName"].ToString(),
                CompanyName = dr["CompanyName"].ToString(),
                CreatedOn = Convert.ToDateTime(dr["CreatedOn"]),
                CreatedBy = dr["CreatedBy"].ToString(),
                //  ZoneName = dr["ZONE_NAME"].ToString()
            });
        }
        return View(list);
    }

视图不受影响。在新窗口上它会引发错误..

如何切换到相应的操作视图? 请帮忙..

【问题讨论】:

    标签: model-view-controller


    【解决方案1】:

    如下更改您的 ajax 代码。

    $.ajax({
                    url: '<%:Url.Action("Click Here","Grid1","Controller Name") %>',
                      data: '{"uid":"' + UserId + '","fdate": "' + FromDate + '","tdate":"' + ToDate + '"}',
                      type: "POST",
                      contentType: "application/json; charset=utf-8",
                      success: function (data) {
                          alert('Success');
                          alert(data);
                          window.open("../GridView/Grid1");
                      }
                  });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-10-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多