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?

How to use FileUpload control inside ASP.Net AJAX Update Panel

There are plenty of questions asked by developers around the globe that they are not able to use FileUpload asp.net control inside ASP.Net Ajax update panel. Their issues are FileUpload control inside Asp.Net Ajax update panel doesn’t hold any file and also return false for HasFile property whenever they upload any file.

There are plenty of questions asked by developers around the globe that they are not able to use FileUpload asp.net control inside ASP.Net Ajax update panel. Their issues are FileUpload control inside Asp.Net Ajax update panel doesn’t hold any file and also return false for HasFile property whenever they upload any file.

Don’t worry! This is because the uploading and manipulations of files are restricted by default in client side for security purpose. That’s why this is not possible to upload files using asynchronous postback in UpdatePanel. you can do it just by changing the Trigger of the upload button from AsyncPostBackTrigger to PostBackTrigger.

Note – Asp.Net Controls that are reside in updatepanel, cause an async postback/update by default. That’s why the page will postback and get partial rendering. Now if for any reason you have control inside an updatepanel which you have to make a full postback rendering, then you need to set it explicitly as a postbacktrigger.

ASP.Net Webform(Aspx) Code :

To use ASP.Net Ajax, you have to add reference ajaxcontroltoolkit.dll in your solution first then you can use below code to upload a file.

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="FileUpload.aspx.cs" Inherits="Open_FileUpload" %>
<!DOCTYPE html>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxtoolkit" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager>  
        <div>
            <asp:UpdatePanel ID="up1" runat="server">
                <ContentTemplate>
                    <asp:FileUpload ID="fileUpload" runat="server" />
                    <asp:Button ID="btnUpload" runat="server" Text="Upload" OnClick="btnUpload_Click" />
                    <br />
                    <asp:Label ID="lblMsg" runat="server" Text=""></asp:Label>
                </ContentTemplate>
                <Triggers>
                    <asp:PostBackTrigger ControlID="btnUpload" />
                </Triggers>
            </asp:UpdatePanel>
        </div>
    </form>
</body>
</html>

Code behind .cs code :

For demo purpose, I am trying to allow the user to upload only jpg or jpeg images.

protected void btnUpload_Click(object sender, EventArgs e)
    {
        string filePath = string.Empty;
        if (fileUpload.HasFile)
        {
            string fileExt = System.IO.Path.GetExtension(fileUpload.FileName);
            if (fileExt.ToLower() != ".jpg" && fileExt.ToLower() != ".jpeg")
            {
                lblMsg.Text = "Upload JPG images only.";
                lblMsg.ForeColor = System.Drawing.Color.Red;
                return;
            }            
            filePath = fileUpload.PostedFile.FileName;
            if (File.Exists(filePath))
            {
                File.Delete(filePath);
            }
            fileUpload.PostedFile.SaveAs(Server.MapPath(@"../UploadedImages/" + filePath.Trim()));          
        }


by RAVI RANJAN KUMAR


Introduction to ASP.NET Core Tutorials | ASP.NET Training | Simpliv

Introduction to ASP.NET Core Tutorials | ASP.NET Training | Simpliv

This course is designed you give you a deep understanding of modern .NET concepts without confusing you or making you lost in the sea of .net technologies that keep springing up now and then. Get behind the modern .NET directions and grasp all that is going on nowadays in the world of .NET.

Description
Last years a great number of technologies came up to the world of .NET platform: nowadays we have the full (classic) .NET framework with CLR as a runtime, Mono with its own runtime, .NET Core with Core CLR, WinRT, UWP and Xamarin, a new JIT compiler RyuJit, .NET Standard, PCL, .Net Native, new Roslyncompiler with open API, NuGet based project management. God’s sake! It’s so simple to get lost in that ocean of technologies. You need to understand the overall picture to feel comfortable today. Didn’t you feel like a small fish in the ocean last time? Well, I did. I questioned myself, "what the hell is going on around me?" I didn’t quite understand the directions in which technologies develop. I didn’t know what to expect, what to learn next. In such situation, you feel helpless. And what we are going to do in the course is that we’re going to eliminate this nasty feeling of being helpless by learning all the most important notions in the modern .NET platform.

Teaching Approach

No fluff, no ranting, no beating the air. I esteem your time. The course material is succinct, yet comprehensive. All important concepts are covered. For absolute beginners, I offer my help on Skype absolutely free if requested. Don't forget that this course has English subtitles, so if you don't understand my accent, feel free to turn them on.

Take this course and you will be satisfied.

Build a deep understanding of modern .NET concepts

If you go behind the modern .NET directions, then this course is for you. This course will bring a whole picture of what's going on nowadays in the world of .NET, so you'll understand what you can and what you can't achieve using specific technologies. This course is like a navigation map.

Content and Overview

The goal of this course is to reveal the whole picture of the .NET world. One of the most profound technologies is the new .NET Core platform, so learning it, is a second primary goal of this course.

Of course, all the way along we will discuss all the other technologies I mentioned above.

This course is built for all kind of C# developers who are interested in learning the .NET platform. This course is beneficial for juniors as well as for seniors who want to stay well-informed about modern .NET platform. I’m sure any student will find something interesting and useful in this course.

The main prerequisite is to be familiar with development on the .NET platform in C#. That’s all you need.

In short, the course covers the following topics:

Classic .net platform, it’s building blocks, the history of this platform
Mono platform, it’s building blocks. You’ll figure out if classic .NET and Mono are compatible. We will compare classic .NET framework and Mono platform
.NET Core is the new cross-platform .NET platform. We will understand what’s different here comparing to other .NET platform and this platform means for the future of the .NET world platform
.NET Native is an interesting ahead-of-time compilation technology. You’ll know that a form of .NET Native comes to .NET Core as well.
Do you really understand what is UWP? How it is related to WinRT and what WinRT actually is?
Roslyn as a compiler platform
NuGet as a system of dependencies management
Installation of .NET Core
Command-Line Interface (CLI) of .NET Core
Deployment in .NET Core: SCD and FDD
The problem of cross-compiling
Portable Class Library (PCL)
.NET Standard
.NET Portability Analyzer
Unit-Testing in .NET Core
Upcoming Changes quick overview
How long is this course: The course is around 2 hours. All are video lectures. You will be able to download all the slides and code samples used in the course.

Keywords related to the course:

.NET Core
C#.NET Core
.NET Standard
NuGet
Core CLR
.NET Ecosystem
Who is the target audience?

Anyone from beginner to senior
Basic knowledge
Need to be familiar with development on the .NET platform in C#
What will you learn
Create, deploy and manage .NET Core applications
Disctinct different technologies: platforms, runtimes, compilers and so on
Create and use .NET Standard Libraries
Understand all the modern .NET concepts
Write unit-tests in .NET Core
To continue:

PHP Vs ASP.NET: How to Choose the Right One?

PHP Vs ASP.NET: How to Choose the Right One?

Are you a business owner looking for PHP web development services or ASP.Net development services, but unable to decide the right technology for your project? Are you looking for the pros and cons of ASP.Net and PHP to take an effective...

Are you a business owner looking for PHP web development services or ASP .Net development services, but unable to decide the right technology for your project? Are you looking for the pros and cons of ASP .Net and PHP to take an effective decision?

We have no doubt about the fact that both of these technologies have become successful ventures, and have developed great websites.

But, the question still remains fresh for all of us, especially those from a non-technical background and the question is: Which platform should we choose at the time of starting with web-apps exercise?

On one side, PHP is a free and open-source platform while ASP .Net is a paid Microsoft platform. PHP is a mix between a programming language and a web framework whereas .NET is a straight application framework.

Now, Let’s have a neat and clean comparison on PHP & DotNet on different parameters.

In the below blog, I have covered the differences between the two and tried to decipher which is the better one.

Read the full blog here: PHP Vs ASP.NET: How to Choose the Right One?