action in mvc controller is being called twice for 2 objects

action in mvc controller is being called twice for 2 objects

I have a weird scenario happens when I send my ajax request that has 2 objects first time it passes the second obj with the right value while the first object is null then second call it passes the first obj with value and the second obj as null here's my ajax method

I have a weird scenario happens when I send my ajax request that has 2 objects first time it passes the second obj with the right value while the first object is null then second call it passes the first obj with value and the second obj as null here's my ajax method

var serializedForm = $(form).serialize();
var postData = {
    merchTask: obj,
    items: arrItems
};
$.ajax({
    type: "POST",
    url: $(form).attr('action'),
    contentType: "application/json; charset=utf-8",
    dataType:'json',
    data: JSON.stringify(postData),
    success: function (response) { 
        alert('done');
    },
     error: function (xhr, status, error) {
         alert("Oops..." + xhr.responseText);
     }
});    

and here's my action in controller

    public ActionResult EditTask(Task merchTask, string[] items)
    {
        short CompanyID = Convert.ToInt16((gSessions.GetSessionValue(gSessionsData.Company) as Company).ID);
        try
        { 
            merchTask.CompanyID = CompanyID; 
            if (merchTask.TaskID != 0)
            {
                taskTemplatesBF.Update(merchTask);
            }
            else
            {
                taskTemplatesBF.InsertMerchTask(merchTask);
            } 
            string[] selectedLst = items;
            foreach (string item in selectedLst)
            { 
                taskTemplatesBF.InsertItemsLink(CompanyID,merchTask.TaskID,merchTask.ItemCode);
            } 
        }
        catch (Exception ex)
        {
            if (ex.InnerException != null)
            {
                ModelState.AddModelError("", ex.InnerException.Message);
            }
            ModelState.AddModelError("", ex.Message);
        }

    return RedirectToAction("TasksTemplates", "Merch");

}

*I found a workaround to send each object separately in different ajax but what's wrong when I send them in one request?

ajax asp.net

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Hire ASP.Net Developers

Looking to outsource your asp dot net development requirement? ASP.Net is a special feature of the DOT Net framework created by Microsoft. At [HourlyDeveloper.io](https://hourlydeveloper.io/ "HourlyDeveloper.io"), we have a team of experienced...

Routing in MVC - ASP.NET Core Demystified

ASP.NET Core MVC has introduced quite a few concepts that new (or new-to-ASP.NET) web developers might have some difficulty getting caught up with. My ASP.NET Core Demystified series is designed to help these developers get started building their own custom, full-fledged, working AASP.NET Core applications. In

What is the ASP.Net Machine Account on my Computer?

Some users have reported the existence of the ASP.Net machine account. In this article, I will discuss what is asp.net machine account in windows 10/7 and how to disable it, asp.net machine account password, and can I delete asp.net machine account? .NET Framework is an application on Windows that requires the installation to run several apps or games. However, when the .NET Framework is downloaded and installed, the application automatically creates an ASP NET machine account.

ASP.NET MVC Application with JQuery, AJAX

Let's have a sample example: We have a submit button in our JQuery AJAX MVC application. Let's try to show a message when it is clicked. ASP.NET MVC Application - Using JQuery, AJAX

Add asp.net Identity in empty project

LIKE | COMMENT | SHARE | SUBSCRIBE Today, in this tutorial you will see the process of adding an ASP.NET Identity to the ASP.NET Web Application developed in...