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 8714571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:37:47+00:00 2026-06-13T05:37:47+00:00

Possible Duplicate: File Upload ASP.NET MVC 3.0 I am trying to just print out

  • 0

Possible Duplicate:
File Upload ASP.NET MVC 3.0

I am trying to just print out the name of the file in the debugger to make sure I am getting it this far:

<EmployeeAuthorize()>
<HttpPost()>
Function SendNewMessage(ByVal file1 As HttpPostedFileBase) As JsonResult


    Dim fileName = Path.GetFileName(file1.FileName)
    Debug.Print(fileName)

    Return Nothing

End Function

I am sending the data with this:

var file1 = $('#file1').val();

            $(this).parent('li').hide();
            $('#pleaseWait').show();

            $.ajax({
                url: '/Message/SendNewMessage',
                type: 'post',
                data: { file1: file1 },
                dataType: 'json',
                success: function (result) {
                    // update with results
                    //alert(JSON.stringify(result));
                    $.each(result, function (i, item) {
                        // do nothing
                    });
                    $('#myDiv').html(JSON.stringify(result));

                },
                error: function (result) {
                    alert('An error occurred when updating the database.  Please contact technical support.  ');

                }
            });

It doesn’t print any data in my console. It gives a NullReferenceException so I can assume it’s not getting the filename at all. What am I doing wrong? Thanks.

  • 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-13T05:37:48+00:00Added an answer on June 13, 2026 at 5:37 am

    Files cannot be uploaded directly through ajax. Instead of it you should use iframe or flash or jquery special plugins.

    For example you can accomplish ajax file uploading through jquery forms plugin.

    Try this, it works:

    Public Class MessageController Inherits System.Web.Mvc.Controller
    
        Function SendNewMessage(ByVal file1 As HttpPostedFileBase) As JsonResult
    
    
            Dim fileName = Path.GetFileName(file1.FileName)
            Debug.Print(fileName)
    
            Return Nothing
    
        End Function
    
    End Class
    

    and this in your view:

    <script type="text/javascript" >
        $(function () {
            var options = {
                beforeSubmit: function (formData, jqForm, options) { },  // pre-submit callback 
                success: function (responseText, statusText, xhr, form) { }   // post-submit callback 
            };
            // bind form using 'ajaxForm' 
            $('#uploadForm').ajaxForm(options);
        });
    </script>
    
    <form action="/Message/SendNewMessage" enctype="multipart/form-data" method="post" id="uploadForm" >
        <input type="file" name="file1" />
        <input type="submit" value="send" /> 
    </form>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Streaming large file uploads to ASP.NET MVC To my understanding, when a
Possible Duplicate: How to increase the max upload file size in ASP.NET? i m
Possible Duplicate: Unable to do File Upload in PHP I am trying to learn
Possible Duplicate: Unique key generation How to automaticly make a new name of file
Possible Duplicate: Max file number can php upload at same time I'm trying to
Possible Duplicate: how to upload a audio file from iphone documents folder to server
Possible Duplicate: Get file name from URI string in C# How to extract file
Possible Duplicate: CSV File Imports in .Net In .net, is there a standard library
Possible Duplicate: HTML Compress File Upload? I have complains from client that my website
Possible Duplicate: multi image upload wrong quantity on file-upload Hey so I have a

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.