小编Pse*_*nym的帖子

在jquery ajax帖子上不断收到400(Bad Request)到MVC控制器

我的ajax调用看起来像这样

$.ajax({ //actually approve or reject the promotion
                url: url,
                type: "POST",
                data: '{'+data.PromotionId+','+data.UserId+','+data.ReasonText+'}',
                dataType: "json",
                //contentType: "application/json; charset=utf-8",
                success: function (data) {
                    if (indicator == 'A') {
                        alert('Promotion approved successfully!');
                    }
                    else {
                        alert('Promotion rejected successfully.');
                    }

                    var homelink = '<%: Url.Action("Index","Home") %>';
                    window.location.href = (homelink);


                    returndata = data;
                },
                error: function (xhRequest, ErrorText, thrownError) {
                    alert("Failed to process promotion correctly, please try again");
                    console.log('xhRequest: ' + xhRequest + "\n");
                    console.log('ErrorText: ' + ErrorText + "\n");
                    console.log('thrownError: ' + …
Run Code Online (Sandbox Code Playgroud)

jquery post asp.net-mvc-4

6
推荐指数
2
解决办法
3万
查看次数

Try-Catch-Finally并非所有代码路径都返回一个值

以下代码应在理想情况下执行标量sql命令:

    public object AsScalar()
    {
        SqlCommand cmd = CreateSqlCommand();
        try
        {

            cmd.Connection.Open();
            return cmd.ExecuteScalar();
        }
        catch (Exception exc)
        {
            log.Error("Exception caught for command: "+_sql, exc);
        }
        finally
        {
            Done(cmd);
        }
    }
Run Code Online (Sandbox Code Playgroud)

但是,我从Visual Studio 2010收到以下错误:

not all code paths return a value   
Run Code Online (Sandbox Code Playgroud)

我认为在try-catch-finally中它总是会执行finally语句,无论是否捕获到异常,但似乎并非如此.

为什么在try-finally工作没有问题时添加catch子句会导致此错误?

c# sql

-1
推荐指数
1
解决办法
1921
查看次数

标签 统计

asp.net-mvc-4 ×1

c# ×1

jquery ×1

post ×1

sql ×1