TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Sneha K
1.2k
527
195.8k
HowPass MultipleParameter to ajax and from ajax toController
Mar 3 2016 4:55 AM
My First Question
Hi i have 4 fields in my view FromDate,ToDate,CustomerName, Count. I want to pass the value of FromDate,ToDate,CustomerName to single Action and have to get the value in Count Textbox. Help me to solve this problem.
My second question
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);
}
The above code get the total SalesOrder count of customer now what i need is i want to get the sales order count of customer(which i select in Dropdown) between FromDate(Which i select in view) and ToDate(which i select in view). how i alter this query for my requirement.
My View
<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>
My jquery
<script src="~/Scripts/jquery-ui-1.8.24.js"></script>
<script src="~/Scripts/jquery-ui-1.8.24.min.js"></script>
<script src="~/Scripts/jquery-1.7.1.min.js"></script>
<script src="~/Scripts/jquery-ui.js"></script>
<script src="~/Scripts/jquery-ui-1.11.0.js"></script>
<script type ="text/javascript">
$(function () {
$.ajax(
//url: "/VisitorsForm/GetCustomers",
'@Url.Action("GetCustomers","Report")', {
type: "GET",
datatype: "Json",
success: function (data) {
$.each(data, function (index, value) {
$('#CustomerID').append('<option value="' + value.CustomerID + '">' + value.DisplayName + '</option>');
});
}
});
});
$("#CustomerID").change(function () {
//$('#ContactID').empty();
alert("hhh");
var req = {
CustomerID: $("#CustomerID").val(),
FromDate: $("#FromDate").val(),
ToDate: $("ToDate").val()
}
$.ajax(
'@Url.Action("GetSalesOrderCountByCustomer", "Report")', {
type: "GET",
dataType: "json",
async: false,
data: JSON.stringify(req),
error: function (ex) {
alert('Failed to retrieve Email.' + ex);
},
beforeSend: function () {
},
success: function (data) {
$("#count").val(data);
}
});
});
</script>
My Controller
[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);
}
}}
Advance Thanks..
Reply
Answers (
10
)
Getting error connection attempt failed
retrieve data from multiple tables using datetimepicker