C# 在mvc4中,如何将多个参数传递到ajax以及从ajax传递到控制器?
我的第一个问题C# 在mvc4中,如何将多个参数传递到ajax以及从ajax传递到控制器?,c#,jquery,ajax,asp.net-mvc-4,C#,Jquery,Ajax,Asp.net Mvc 4,我的第一个问题 public JsonResult GetSalesOrderCountByCustomer(Guid customerID, DateTime fromdate,DateTime Todate) { var salescount = (from sc in db.SalesOrders where sc.CustomerID == customerID select sc.SalesOrderID).Count(); return J
public JsonResult GetSalesOrderCountByCustomer(Guid customerID, DateTime fromdate,DateTime Todate)
{
var salescount = (from sc in db.SalesOrders where sc.CustomerID == customerID select sc.SalesOrderID).Count();
return Json(salescount, JsonRequestBehavior.AllowGet);
}
嗨,我的视图中有4个字段:FromDate、ToDate、CustomerName、Count。
我想将FromDate、ToDate、CustomerName的值传递给单个操作,并且必须在Count文本框中获取该值。帮我解决这个问题
我的第二个问题
public JsonResult GetSalesOrderCountByCustomer(Guid customerID, DateTime fromdate,DateTime Todate)
{
var salescount = (from sc in db.SalesOrders where sc.CustomerID == customerID select sc.SalesOrderID).Count();
return Json(salescount, JsonRequestBehavior.AllowGet);
}
上面的代码获取客户的销售订单总数现在我需要的是获取FromDate(我在视图中选择)和ToDate(我在视图中选择)之间的客户销售订单总数(我在下拉列表中选择)。我如何根据自己的需求修改此查询
我的观点
<div class="col-sm-4">
<div class="form-group">
@Html.Label("FromDate", new { @class = "control-label" })
@Html.TextBoxFor(model => model.FromDate, new { @class = "form-control", type = "text"})
</div>
</div>
<div class="col-sm-4">
<div class="form-group">
@Html.LabelFor(model => model.ToDate)
@Html.TextBoxFor(model => model.ToDate, new { @class = "form-control", type = "text" })
</div>
</div>
<div class="col-sm-4">
<div class="form-group">
@Html.LabelFor(model => model.CustomerName)
@Html.DropDownList("CustomerID","Select")
@Html.ValidationMessageFor(model => model.CustomerName)
</div>
</div>
<div class="col-sm-4">
<div class="form-group">
@Html.LabelFor(model => model.count)
@Html.TextBoxFor(model => model.count, new { @class = "form-control", type = "text"})
@Html.ValidationMessageFor(model => model.count)
</div>
</div>
javascript对象属性名称的大小写应与实际使用的参数相同。请更正它并让我们知道您的
saleorder
类以了解查询。同时让我们知道您的控制器操作是否被点击,您是否正在获得传递的值。好的,让我检查一下,也请更正一些代码缩进。Manoj我更改属性名称,与参数名称相同,如果我运行应用程序,它只点击get customer操作,而且不工作。它显示无法检索的警报消息您是否使用Firebug或Chrome开发人员工具调试javascript?您能告诉我们服务器的错误是什么吗?您确定在客户端正确设置了值吗?
[HttpGet]
public ActionResult NewExistingCustomer( CustomerViewModel cvm)
{
ViewBag.CustomerID = new SelectList(db.Customers, "CustomerID", "DisplayName");
return View();
}
public JsonResult GetCustomers()
{
return Json(db.Customers.ToList(), JsonRequestBehavior.AllowGet);
}
public JsonResult GetSalesOrderCountByCustomer(Guid customerID, DateTime fromdate,DateTime Todate)
{
var salescount = (from sc in db.SalesOrders where sc.CustomerID == customerID select sc.SalesOrderID).Count();
return Json(salescount, JsonRequestBehavior.AllowGet);
}
}}