【发布时间】:2014-04-18 05:36:24
【问题描述】:
我有一个页面,它首先要求提供一些详细信息,然后在其下方的 div 中返回部分视图。
这是我的 Ajax(在我测试之后,正在获取详细信息并将其传递给控制器):
<script type="text/javascript">
function Filter() {
var startd = $('#startdt').val();
var endd = $('#enddt').val();
var itemname = $("#Products option:selected").val();
var param = { StartD: startd, EndD: endd, ItemName: itemname };
$.ajax({
url: '@Url.Action("FilterTransaction")',
type: "POST",
datatype: "html",
UpdateTargetId: "divResult",
data: param,
error: function (xmlHttpRequest, errorText, thrownError) {
alert(xmlHttpRequest + "|" + errorText + "|" + thrownError);
},
success: function (data) {
$('divResult').html(result);
}
});
}
</script>
这是控制器(方法和变量都被正确处理):
public PartialViewResult FilterTransaction(string StartD, string EndD, string ItemName)
{
try
{
int productid = new ProductService.ProductsServiceClient().GetProductID(ItemName);
Product p = new ProductService.ProductsServiceClient().GetProduct(productid);
ViewBag.ItemNo = productid;
ViewBag.ItemName = p.Name;
ViewBag.AmmountP = p.Price;
int orderid = new OrderService.OrderServiceClient().GetOrderID(productid, User.Identity.Name);
Order o = new OrderService.OrderServiceClient().GetOrder(orderid);
ViewBag.DatePurchased = o.Date;
ViewBag.WarrantyExpiryDate = o.Date.AddYears(2);
DateTime fromd = Convert.ToDateTime(StartD);
DateTime todate = Convert.ToDateTime(EndD);
todate = todate.AddDays(1);
List<PrintViewFD> printv = new List<PrintViewFD>();
foreach (FaultDetail fs in new FaultService.FaultServiceClient().GetListOfFaultDetailsbetweenDATES(orderid, productid, fromd, todate))
{
PrintViewFD pvd = new PrintViewFD();
pvd.date = fs.Date.ToString();
pvd.details = fs.Details;
pvd.faultid = fs.FaultID;
FaultStatu fss = new FaultService.FaultServiceClient().GetStatus(fs.FaultStatusID);
pvd.status = fss.Status;
printv.Add(pvd);
}
ViewBag.FaultDetailsLIST = printv;
return PartialView("_filtertransactions");
}
catch
{
return PartialView("_filtertransactions");
}
}
我调试了这个函数,它同时进入了控制器方法和局部视图。唯一的问题是局部视图没有显示在视图中。我认为它与ajax有关!
这是应该显示它的 div:
<div id="divResult">test</div>
【问题讨论】:
-
$('divResult')->$('#divResult')
标签: jquery ajax asp.net-mvc asp.net-mvc-4