Step by step migration of ASP.NET Core 2.2 to 3.1

In order to upgrade/migrate asp.net core version to 3.1 following steps to be perform. Download and install Visual Studio 2019 version 16.4 or higher. Download and install .NET Core 3.1  https://dotnet.microsoft.com/download/dotnet-core/3.1 Upgrade the projects of solution to .NET Core 3.1 , because ASP.NET Core 3.1 requires it. Update existing Nuget packages to a version compatible with ASP.NET Core 3.1 in each project Use IHost interface from a IHostBuilder instead of building and running a IWebHost from a IWebHostBuilder in Program.cs public static IHostBuilder CreateWebHostBuilder(string[] args) => Host.CreateDefaultBuilder(args) .ConfigureWebHostDefaults(webBuilder => { webBuilder.UseKestrel() .UseSerilog() .UseStartup<Startup>(); }) Change AddMvc method has been replaced by AddControllers in Startup.cs of each projects. In Startup.cs, UseMvc method to b

File extension validation using javascript in MVC

This is article which demonstrate the validation of allowed file extension for upload of files in MVC using javascript. In this article i have used validation for valid image format like Jpeg, Jpg,Gif and png image format. If users ties to upload any other file apart from above mentioned file then the javascript function will shows proper message to user to select appropriate files.

I have used html input file control for uploading of files in MVC application.

following is the html code for it.


<body>
    <div style="height:50px; padding-bottom:20px;">
      @using (@Html.BeginForm("Create","FileUpload",FormMethod.Post,new{ enctype = "multipart/form-data"}))
{

<input type="file" id="file1" name="sdf" style=" margin-top:0px;" onchange="if( CheckExtention(this.value) ) {parent.ShowHideImage(true);this.form.submit();}" />



}
  
    </div>
</body>

and following is the javascript code to implement the validation


<script type="text/javascript">
  

    function CheckExtention(file)
    {
 var ext=  file.substr(file.lastIndexOf('.'),4).toLowerCase();
 
    if(ext!='.jpg' && ext!='.png' && ext!='.jpeg' && ext!=".gif")
    {
        alert('Only Jpg,png,Jpeg,or gif format allowed');
        
        var file = document.getElementById("file1");
        file.value = "";
        return false;

    }
    else 
    {
        return true;
    }

    }

</script>

I hope all you guys understood the concept.

Kindly let me know if you have any queries

Comments

Popular posts from this blog

Restore the lost focus of Auto post back controls in asp.net update Panel control

Add Comma automatically while entering amounts in textbox using Javascript

Devexpress Datebox date formatting in angular 6 with example