来自Ajax.BeginForm的响应无法获取文本框值

时间:2016-01-20 05:23:54

标签: c# ajax asp.net-mvc asp.net-mvc-4

我在使用ajax时遇到了一些麻烦。我有两个日期选择器和一个按钮。按下按钮时,需要通过Ajax.BeginForm()方法将datepicker文本框中的值传递给控制器​​操作方法,并显示部分视图。但是当我按下按钮时没有任何反应。这是代码:

控制器:

[HttpPost]
public ActionResult CustomerFilter(string fromDate, string toDate)
{            
    IEnumerable<DC_MASTERReport> dcms = null;    
    try
    {                
        dcms = from t in db.DC_ITEM
               join t0 in db.DC_MASTER on t.DC_NO equals t0.DC_NO
               .....
               where
                 t.ITEM_MASTER.ITEM_CODE == t1.ITEM_CODE && (DateTime.ParseExact(t0.PSR_LOAD_DATE_TIME, "yyyy-MM-dd HH:mm:ss", null).Date.CompareTo(fromDate) >= 0 && DateTime.ParseExact(t0.PSR_LOAD_DATE_TIME, "yyyy-MM-dd HH:mm:ss", null).Date.CompareTo(toDate) <= 0)                                             
               select new DC_MASTERReport
               {
                   DC_NO = t0.DC_NO,
                   DC_STYPE = t0.DC_STYPE,
                   ....                          
                };
        return PartialView("DeliveryList", dcms);                
    }
    catch (Exception ex)
    {
        TempData["Error"] = "Some error occured while loading the page contact help desk";
        ExceptionUtility.LogException(ex, "Delivery-CustomerFilter-POST");
        return PartialView("DeliveryList", dcms);
    }
}

我的初始视图 - Index.cshtml:

@using (Ajax.BeginForm("CustomerFilter", "Delivery", new System.Web.Mvc.Ajax.AjaxOptions
    {
        InsertionMode = System.Web.Mvc.Ajax.InsertionMode.Replace,
        HttpMethod = "POST",
        UpdateTargetId = "deliverylist"
     }))
{               
    <input id="fromDate" name="fromDate" type="text" />
    <input id="toDate" name="toDate" type="text" />
    <input type="button" value="View" id="BtnSubmit" text="Proceed" runat="server" />
}

// Delivery List Partial View
<div id="deliverylist">
    @Html.Partial("DeliveryList")
</div>

// Java script for Date Picker
<script type="text/javascript">
    $(document).ready(function () {        
        $("#fromDate").datepicker({ dateFormat: 'yy-mm-dd' });
        $("#toDate").datepicker({ dateFormat: 'yy-mm-dd' });

        $("#toDate").change(function () {
            var fromDate = $("#fromDate").val();
            if (fromDate == '') {
                alert("Please select From Date");
                return false;
            }           
        });
    });
</script>

DeliveryList.cshtml是部分视图。

实际上,这是使用Ajax.BeginForm()方法

的正确方法吗?

0 个答案:

没有答案