0

I'm developing asp.net mvc 5 web application. I want to send parameters to aspx web-form code-behind method using ajax in asp.net mvc

I have following aspx web page and relevant files

enter image description here

within that Incomplete_Prodcut.aspx.cs codebehind file I have webmethod which is

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

This is what I did upto now

.................
@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>


}

but once I click "Generate Report" button Im getting following error

Internal Server Error

enter image description here

5
  • Is your URL correct ? Commented Sep 22, 2015 at 6:39
  • Please look at this answer stackoverflow.com/questions/27917255/… Commented Sep 22, 2015 at 6:42
  • @MairajAhmad yes url is fine Commented Sep 22, 2015 at 6:46
  • See the console of browser there you can see detailed error. Post that error. Commented Sep 22, 2015 at 6:48
  • The debug it's been hit on the server ? regardless if the parameters are nulls Commented Sep 22, 2015 at 17:59

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.