Click here to Skip to main content
15,884,176 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have a fairly larger form which has multiple fields, I need to pass the values of those fields to an action method, assigns some values to another view and opens it. I have been trying to post those values using ajax post the action method is getting executed but the View stays the same.
I have not used any model binding for the first view from where I am posting the values into an action method, hence I tried to use the ajax call, is there any way I can post the values to action method and transfer to new view that I wanted after action method execution by using ajax call.
I know I can achieve it by using Model binding and submit but I don't have model for the View so can I do it by using ajax call itself.
My ajax call and action methods are as below:
$("#btnChangeReport").click(function ()
{
    debugger;
    var res;
    var token = $('[name=__RequestVerificationToken]').val();

    $.ajax({
        type: "POST",
        url: '@Url.Action("ShowLegalEntityReport", "Report")',
        contentType: "application/json;charset=utf-8",
        dataType: 'json',
        async: false,
        headers: { '__RequestVerificationToken': token },
        data: JSON.stringify({
            'legalEntityNumber': txtLegalEntityNumber.value, 'lENumOperator': "", 'legalEntityName': txtLegalEntityName.value, 'lENameOperator': ""
            , 'taxId': txtTaxId.value, 'taxIdOperator': "", 'submittingCounty': $('#idDDLForCounty').val(), 'submCountyOperator': "", 'legalEntityCity': txtLegalEntityCity.value, 'lECityOperator': ""
        }),
        success: function (result)
        {

        }
    });
});


Action method is as below:
public ActionResult ShowLegalEntityReport(string legalEntityNumber, string lENumOperator, string legalEntityName, string lENameOperator
    , string taxId, string taxIdOperator, string submittingCounty, string submCountyOperator, string legalEntityCity, string lECityOperator)
{
    ReportViewer reportViewer = new ReportViewer();
    reportViewer.ProcessingMode = ProcessingMode.Local;
    reportViewer.SizeToReportContent = true;
    reportViewer.Width = Unit.Percentage(900);
    reportViewer.Height = Unit.Percentage(700);

    DataRetrieveServiceClient drsc = new DataRetrieveServiceClient();

    DataTable dt = CommonFunctions.ToDataTable(drsc.GetLegalEntityReport(legalEntityNumber, lENumOperator, legalEntityName, lENameOperator, taxId, taxIdOperator
        , submittingCounty, submCountyOperator, legalEntityCity, lECityOperator));

    reportViewer.LocalReport.ReportPath = Request.MapPath(Request.ApplicationPath) + @"\Reports\LegalEntityReport.rdlc";
    reportViewer.LocalReport.DataSources.Add(new ReportDataSource("LegalEntityDataSet", dt));

    ViewBag.ReportViewer = reportViewer;

    return View();
}


Please help me in this regards any help is appreciated - thanks in advance

What I have tried:

googling searching asking colleagues any help that's possible
Posted
Comments
F-ES Sitecore 31-Oct-18 6:13am    
Your view's html is being returned in the "result" param of your success method, but you're not doing anything with it so you're calling the action and ignoring the results. If you want that html to appear on the page somewhere then you'll need to inject it into the DOM. That's only really going to work if it is a partial view. If it's a full view and you want the entire page to change then don't use ajax at all, just post the form, ajax is only really used when you want to update a part of the page.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900