Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8975073
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:47:28+00:00 2026-06-15T18:47:28+00:00

I have a form in which I need to call two action methods, one

  • 0

I have a form in which I need to call two action methods, one after the other. This is how the flow goes.

  • First I check if the prerequisite data is entered by the user. If not then I show a message that user needs to enter the data first.
  • If all the prerequisite data is entered, I call an action method which return data. If there is no data returned then I show a message “No data found” on the same page.
  • If data is returned then I call another action method present in a different controller, which returns a view with all the data, in a new tab.

The View:

@using (Ajax.BeginForm("Index", "OrderListItems", null, new AjaxOptions { OnBegin = "verifyRequiredData"}, new { @id = "formCreateOrderListReport", @target = "_blank" }))
{
    //Contains controls and a button 
}

The Script in this View:

        function verifyRequiredData() {            
            if ($("#dtScheduledDate").val() == "") {

                $('#dvValidationSummary').html("");
                var errorMessage = "";

                errorMessage = "<span>Please correct the following errors:</span><ul>";
                errorMessage += "<li>Please enter Scheduled date</li>";

                $('#dvValidationSummary').append(errorMessage);
                $('#dvValidationSummary').removeClass('validation-summary-valid').addClass('validation-summary-errors');

                return false;
            }
            else {
                $('#dvValidationSummary').addClass('validation-summary-valid').removeClass('validation-summary-errors');
                $('#dvValidationSummary').html("");

                $.ajax({
                    type: "GET",
                    url: '@Url.Action("GetOrderListReport", "OrderList")',                    
                    data: {
                        ScheduledDate: $("#dtScheduledDate").val(),
                        Crews: $('#selAddCrewMembers').val(),
                        Priorities: $('#selPriority').val(),
                        ServiceTypes: $('#selServiceTypes').val(),
                        IsMeterInfoRequired: $('#chkPrintMeterInfo').val()
                    },
                    cache: false,                    
                    success: function (data) {
                        debugger;
                        if (data !== "No data found") {
                            //var newUrl = '@Url.Action("Index", "OrderListItems")';
                            //window.open(newUrl, '_blank');
                            return true;
                        } else {
                            //Show message "No data found"
                            return false;
                        }
                    }
                });
                return false;
            }
        }

The “GetOrderListReport” Action method in “OrderList” Controller:

 public ActionResult GetOrderListReport(OrderListModel model)
 {
     var contract = new OrderReportDrilldownParamDataContract
     {             
         ScheduledDate = model.ScheduledDate
         //Setting other properties as well           
     };
     var result = OrderDataModel.GetOrderList(contract);

     if (string.IsNullOrWhiteSpace(result) || string.IsNullOrEmpty(result))
     {
         return Json("No data found", JsonRequestBehavior.AllowGet);             
     }

     var deserializedData = SO.Core.ExtensionMethods.DeserializeObjectFromJson<OrderReportDrilldownDataContract>(result);

     // send it to index method for list
     TempData["DataContract"] = deserializedData;
     return Json(deserializedData, JsonRequestBehavior.AllowGet);
    }

The last action method present in OrderListItems Controller, the result of which needs to be shown in a new tab:

public ActionResult Index()
{
    var deserializedData = TempData["DataContract"] as OrderReportDrilldownDataContract;
    var model = new OrderListItemViewModel(deserializedData);
    return View(model);
}

The problem is that I am not seeing this data in a new tab, although I have used @target = “_blank” in the Ajax.BeginForm. I have also tried to use window.open(newUrl, ‘_blank’) as can be seen above. But still the result is not shown in a new tab.

Please assist as to where I am going wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T18:47:29+00:00Added an answer on June 15, 2026 at 6:47 pm

    If you are using the Ajax.BeginForm you shouldn’t also be doing an ajax post, as the unobtrusive ajax library will automatically perform an ajax post when submitting the form.

    Also, if you use a view model with data annotation validations and client unobtrusive validations, then there would be no need for you to manually validate the data in the begin ajax callback as the form won’t be submitted if any validation errors are found.

    The only javascript code you need to add in this scenario is a piece of code for the ajax success callback. That will look as the one you currently have, but you need to take into account that opening in new tabs depends on the browser and user settings. It may even be considered as a pop-up by the browser and blocked, requiring the user intervention to allow them as in IE8. You can give it a try on this fiddle.

    So this would be your model:

    public class OrderListModel 
    {
        [Required]
        public DateTime ScheduledDate { get; set; }
    
        //the other properties of the OrderListModel
    }
    

    The form will be posted using unobtrusive Ajax to the GetOrderListReport of the OrderList controller. On the sucess callback you will check for the response and when it is different from “No data found”, you will then manually open the OrderListItems page on a new tab.

    This would be your view:

    @model someNamespace.OrderListModel
    
    <script type="text/javascript">
        function ViewOrderListItems(data){
            debugger;
            if (data !== "No data found") {
                var newUrl = '@Url.Action("Index", "OrderListItems")';
                //this will work or not depending on browser and user settings.
                //passing _newtab may work in Firefox too.
                window.open(newUrl, '_blank');
            } else {
                //Show message "No data found" somewhere in the current page
            }
        }
    </script>
    
    @using (Ajax.BeginForm("GetOrderListReport", "OrderList", null, 
                          new AjaxOptions { OnSucces= "ViewOrderListItems"}, 
                          new { @id = "formCreateOrderListReport" }))
    {
        @Html.ValidationSummary(false)
    
        //input and submit buttons
        //for inputs, make sure to use the helpers like @Html.TextBoxFor(), @Html.CheckBoxFor(), etc
        //so the unobtrusive validation attributes are added to your input elements.
        //You may consider using @Html.ValidationMessageFor() so error messages are displayed next to the inputs instead in the validation summary
        //Example:
        <div>
            @Html.LabelFor(m => m.ScheduledDate)
        </div>
        <div>
            @Html.TextBoxFor(m => m.ScheduledDate, new {id = "dtScheduledDate"})
            @Html.ValidationMessageFor(m => m.ScheduledDate)
        </div>
    
        <input type="submit" value="Get Report" />
    }
    

    With this in place, you should be able to post the data in the initial page using ajax. Then based on the response received you will open another window\tab (as mentioned, depending on browser and user settings this may be opened in a new window or even be blocked) with the second page content (OrderListItems).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form which contains rows like this one. I need to be
i have a form button in the form,which i need to perform basic action
I have this form, in which i need to populate a combo box with
I need to make the program which have one form that contains PNG image
I have two action methods. One of them submits the inserted data of a
I have an InfoPath form which I need to conditionally disable it's OnChange events.
I have a form builder class which inherits from AbstractType and I need to
I have a link which return form with different ID's, and i need to
I need to have a checkbox which ajax-submits a form. The following code throws
I have a control which is mounted within a form. I need to implement

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.