$("#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);
}
查看没有影响。在新窗口中它会抛出错误..
如何更改相应的操作视图? 请帮忙..
答案 0 :(得分:0)
更改您的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");
}
});