使用asp.net mvc中的ajax将参数发送到aspx webform codebehind方法

时间:2015-09-22 06:06:14

标签: javascript c# ajax asp.net-mvc webforms

我正在开发asp.net mvc 5 Web应用程序。 我想在asp.net mvc

中使用ajax将参数发送到aspx web-form代码隐藏方法

我有以下aspx网页和相关文件

enter image description here

Incomplete_Prodcut.aspx.cs 代码隐藏文件中我有webmethod

[WebMethod]    
public static string OnSubmit(string type, string category, string country, string subsidary, string dateHERE)
{
    return "it worked";
}

这就是我现在所做的事情

.................
@using (Html.BeginForm())
{

    @Html.AntiForgeryToken()
    @Html.ValidationSummary(true, "", new { @class = "text-danger" })

    <div class="form-group"></div>


    <div class="row">

        <div class="col-xs-6">
            <div class="form-group">
                @Html.LabelFor(m => m.Type, htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.DropDownListFor(m => m.Type, Model.TypeList, "Select the type", new { @class = "form-control" })
                    @Html.ValidationMessageFor(model => model.Type, "", new { @class = "text-danger" })
                </div>
            </div>
        </div>
..............................

    <div class="row">
        <div class="form-group">
            <div class="col-md-offset-2 col-md-10">
                <input type="button" id="report"  value="Generate Report" class="btn btn-success submit" /> 
            </div>                      
        </div>
    </div>



}







@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
    @Scripts.Render("~/bundles/jqueryui")
         ................................


        <script type="text/javascript">

            $('#report').click(function () {

                var type = $('#Type');
                var category = $('#Category');
                var country = $('#Country');
                var subsidary = $('#Subsidary');
                var dateHERE = $('#Date');

                var dataValue = { type: type.val(), category: category.val(), country: country.val(), subsidary: subsidary.val(), dateHERE: dateHERE.val() };

            $.ajax({
                type: "POST",
                url: "/Report/Incomplete_Prodcut.aspx/OnSubmit",
                data: dataValue,
                contentType: 'application/json; charset=utf-8',
                dataType: 'json',

                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    alert("Request: " + XMLHttpRequest.toString() + "\n\nStatus: " + textStatus + "\n\nError: " + errorThrown);
                },
                success: function (result) {
                    alert("We returned: " + result);
                }
            });
        });


    </script>


}

但是一旦我点击“生成报告”按钮我就会收到以下错误

  

内部服务器错误

enter image description here

0 个答案:

没有答案