为什么这个ajax调用失败,导致我的控制器方法无法被调用? [英] Why is this ajax call failing, causing my controller method to not get called?
问题描述
我正在点击这个ajax调用的错误部分,看到'btnTestProduceUsageSettings'中的错误':
I'm hitting the "error" part of this ajax call, seeing "'error in btnTestProduceUsageSettings'":
$("#btnTestProduceUsageSettings").click(function () {
var dom = $('#dayofmonthselect').val();
var ord = $('#ordinalselect').val();
var dow = $('#dayofweekselect').val();
var wom = $('#weekormonthselect').val();
var daterangefromval = $('#produsagefrom').val();
var daterangetoval = $('#produsageto').val();
var unitval = $('#unitsselect').val();
var reportId = 1;
$.ajax({
type: 'GET',
url: '@Url.Action("GetTestSettingVals", "TestSettings")',
data: { unit: unitval, report: reportId, dayofmonth: dom, ordinal: ord, dayofweek: dow,
weekormonth: wom, fromval: daterangefromval, toval: daterangetoval },
cache: false,
success: function (returneddata) {
var nextgendate = returneddata.testsettings.NextGenDate;
var nextfromdate = returneddata.testsettings.NextFromDate;
var nexttodate = returneddata.testsettings.NextToDate;
alert('If you save the current configuration, the Produce Usage report would next be sent on ' + nextgendate + ' and cover data from ' + nextfromdate + ' to ' + nexttodate);
},
error: function () {
alert('error in btnTestProduceUsageSettings');
}
});
});
JSLint没有发现任何真正的错误(超出其通常的挑剔)。至少有一个参数始终为空。我想知道这是问题,但我试过这个,只是为了确保空值不会导致问题:
。 。 。
var ord =''; // $('#ordinalselect')。val();
var dow =''; // $('#dayofweekselect')。val();
var wom =''; // $('#weekormonthselect')。val();
。 。 。
...它仍然失败。
应该调用的Controller方法由于失败,根本没有达成。定义如下:
public JsonResult GetTestSettingVals(string unit,int RptID,string dayOfMonthGen,
string ordinalGen,string dayOfWeekGen,string weekOrMonthGen,
int fromIntDateRange,int toIntDateRange)
因此,通过Chrom Dev Tools中的断点逐步执行代码,我达到了$。 ajax({行,但不是Controller方法中的断点(在Visual Studio中),在最后一行中有一个如下所示:
公共类TestSettingsController:控制器
{
public JsonResult GetTestSettingVals(string unit,int RptID,string dayOfMonthGen,string ordinalGen,string dayOfWeekGen,string weekOrMonthGen,int fromIntDateRange,int toIntDateRange)
{
TestSettingsModel model = new TestSettingsModel();
我还有其他的ajax / controller组合设计工作正常的方式相同,所以我看不出挂机在这里...我在这里错过了一个明显或隐蔽的问题吗?
我尝试了什么:
我想知道是否发送一些零值可能是问题,但我试过这个,只是为了确保空值不会导致问题:
。 。 。
var ord =''; // $('#ordinalselect')。val();
var dow =''; // $('#dayofweekselect')。val();
var wom =''; // $('#weekormonthselect')。val();
。 。 。
...它仍然失败。
应该调用的Controller方法由于失败,根本没有达成。定义如下:
public JsonResult GetTestSettingVals(string unit,int RptID,string dayOfMonthGen,
string ordinalGen,string dayOfWeekGen,string weekOrMonthGen,
int fromIntDateRange,int toIntDateRange)
因此,通过Chrom Dev Tools中的断点逐步执行代码,我达到了$。 ajax({行,但不是Controller方法中的断点(在Visual Studio中),在最后一行中有一个如下所示:
公共类TestSettingsController:控制器
{
public JsonResult GetTestSettingVals(string unit,int RptID,string dayOfMonthGen,string ordinalGen,string dayOfWeekGen,string weekOrMonthGen,int fromIntDateRange,int toIntDateRange)
{
TestSettingsModel model = new TestSettingsModel();
我还有其他的ajax / controller组合设计工作正常的方式相同,所以我看不到挂断在这里...我在这里错过了一个明显或隐蔽的问题吗?
JSLint doesn't find anything really wrong with it (beyond its usual nitpickiness). At least one of the params is always null. I wondered it that was the problem, but I tried this, just to make sure the null values were not causing the problem:
. . .
var ord = ''; //$('#ordinalselect').val();
var dow = ''; //$('#dayofweekselect').val();
var wom = ''; //$('#weekormonthselect').val();
. . .
...and it still failed.
The Controller method that is supposed to be called isn't being reached at all because of the failure. It is defined:
public JsonResult GetTestSettingVals(string unit, int RptID, string dayOfMonthGen,
string ordinalGen, string dayOfWeekGen, string weekOrMonthGen,
int fromIntDateRange, int toIntDateRange)
So stepping through the code, with a breakpoint in Chrom Dev Tools, I reach the "$.ajax({" line, but not the breakpoint in the Controller method (in Visual Studio), which has one on the last line shown below:
public class TestSettingsController : Controller
{
public JsonResult GetTestSettingVals(string unit, int RptID, string dayOfMonthGen, string ordinalGen, string dayOfWeekGen, string weekOrMonthGen, int fromIntDateRange, int toIntDateRange)
{
TestSettingsModel model = new TestSettingsModel();
I have other ajax/controller combinations designed the same way that work fine, so I can't see what the hangup is here...am I missing an either obvious or well-concealed problem here?
What I have tried:
I wondered if sending some null vals might be the problem, but I tried this, just to make sure the null values were not causing the problem:
. . .
var ord = ''; //$('#ordinalselect').val();
var dow = ''; //$('#dayofweekselect').val();
var wom = ''; //$('#weekormonthselect').val();
. . .
...and it still failed.
The Controller method that is supposed to be called isn't being reached at all because of the failure. It is defined:
public JsonResult GetTestSettingVals(string unit, int RptID, string dayOfMonthGen,
string ordinalGen, string dayOfWeekGen, string weekOrMonthGen,
int fromIntDateRange, int toIntDateRange)
So stepping through the code, with a breakpoint in Chrom Dev Tools, I reach the "$.ajax({" line, but not the breakpoint in the Controller method (in Visual Studio), which has one on the last line shown below:
public class TestSettingsController : Controller
{
public JsonResult GetTestSettingVals(string unit, int RptID, string dayOfMonthGen, string ordinalGen, string dayOfWeekGen, string weekOrMonthGen, int fromIntDateRange, int toIntDateRange)
{
TestSettingsModel model = new TestSettingsModel();
I have other ajax/controller combinations designed the same way that work fine, so I can't see what the hangup is here...am I missing an either obvious or well-concealed problem here?
推荐答案
( #btnTestProduceUsageSettings)。click( function (){
var dom =
("#btnTestProduceUsageSettings").click(function () { var dom =
(' #dayofmonthselect')。val();
var ord =
('#dayofmonthselect').val(); var ord =
(' #ordinalselect'跨度>)VAL();
var dow =
('#ordinalselect').val(); var dow =
这篇关于为什么这个ajax调用失败,导致我的控制器方法无法被调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!