Feed Buzzard
  • Fitness Trackers
  • General
  • Tech
  • Wearable Tech
  • World Tech
  • World Tech Code
  • Contact Us
No Result
View All Result
  • Fitness Trackers
  • General
  • Tech
  • Wearable Tech
  • World Tech
  • World Tech Code
  • Contact Us
No Result
View All Result
Feed Buzzard
No Result
View All Result
Home World Tech

Registration form with image upload in MVC using jquery Ajax

Gordon James by Gordon James
October 3, 2021
in World Tech
0
0
SHARES
26
VIEWS
Share on FacebookShare on Twitter

In this article on asp.net MVC, we will learn how to create a complete system of simple and custom registration forms with image uploads using an entity framework with jquery validation in MVC.

We will create the registration functionality using the entity framework. This article is perfect for those who are new to asp.net MVC and want to know the best way to register users with image upload control.

Let’s start by creating the mvc project, I also created a folder to store the downloaded image in.

Step 1

Let’s add an entity frame to work with databases by following the step description in the image

  • Right-click on the template folder=>Add=>New item
  • Select Data from the left menu and then the Ado Entity frame.

Step 2 – Create a controller

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using UploadFileMvc.Models ;

namespace UploadFileMvc.Controllers
{
public class AccountController : Controller
{
// GET : Account
public ActionResult Index()
{
DemoDBEntities db = new DemoDBEntities();
return View(db.TblCompanyUsers.ToList());
}
// Post:Registration
[HttpPost] public ActionResult UserRegistration()
{
try
{

// Save the form data
string FullName = Request.Form[Full Name];
string Email = Request.Form[Email];
string Password = Request.Form[Password];
if(!IsEmailExist(Email))
{
if (Request.Files.Count > 0) // check if the Request object contains a file
{
try
{
using (DemoDBEntities db = new DemoDBEntities())
{
HttpPostedFileBase file = Request.Files[0];
string fname = file.FileName;
// retrieve the full path to the folder and save the file there.
fname = Path.Combine(Server.MapPath(~/Images/), fname);
file.SaveAs(fname);
TblCompanyUser userobj = new TblCompanyUser
{
Email_Id = Email,
FullName = FullName,
ProfilePicture= /Images/+ file.FileName
};
db.TblCompanyUsers.Add(userobj);
if (db.SaveChanges() > 0)
{
//Set MVC and Login Authentication
return Json(User registered successfully !) ;
}
more
{
return Json(Something went wrong, try again later !);
}
}
}
catch (exception ex)
{
return Json(ex.Message);
}
}
else
{
return Json(Files not selected.);
}
}
else
{
return Json(Email already exists, try with another one!);
}

}
catch (exception e)
{
ModelState.AddModelError(, e.Message);
}
return View();
}
private bool IsEmailExist(string email)
{
bool IsEmailExist = false;
using (DemoDBEntities db = new DemoDBEntities())
{
int count = db.TblCompanyUsers.Where(a => a.Email_Id == email).Count();
if (count > 0)
{
IsEmailExist = true;
}
}
return IsEmailExist;
}
}
}

Let’s add the view and copy and paste the code below.

@model IEnumerable
@{
ViewBag.Title = Index;
}

Index

@foreach (var item in model){}

ID Name Email
@item.UserId @item.FullName @entry.email_id

Registration form with image upload in MVC with jquery Ajax

Name

E-mail

Password

Profile Fig.

 

Related Tags:

image upload in mvc using ajax,how to upload image in mvc using jquery,file upload in mvc using ajax,upload file using ajax,jquery file upload mvc,uploading both data and files in one form using ajax mvc,Privacy settings,How Search works,upload file and json data in the same post request using jquery ajax,jquery sending file with ajax to mvc controller

Total
0
Shares
Share 0
Tweet 0
Pin it 0
Share 0
Gordon James

Gordon James

Related Posts

Dan Schatt of Earnity Explain How to Build Wealth with Crypto
World Tech

Dan Schatt of Earnity Explain How to Build Wealth with Crypto

May 17, 2022
World Tech

Rewriteguru – A Platform That Provides a Facility to Reuse Your Previous Contents

April 22, 2022
World Tech

How Live Streaming Changed The Gaming Industry

April 20, 2022
Next Post

11 Best Anime Apps in 2021

Booster-in-chied Tesla CEO Elon Musk Send Dogecoin to the Moon

How To Fix Minecraft Won’t Launch in Windows 10

No Result
View All Result

Recommended

How Casino Projects are Created and Who Supplies Its Components

2 hours ago

How To Break Into Working In Tech

2 hours ago

A Creative Guide to Services and Solutions Offered at eSoft

3 hours ago

Why You Need To Consider Asia Pulp & Paper

3 hours ago

Categories

  • Fitness Trackers
  • General
  • Latest
  • Tech
  • Technology and Computing
  • Wearable Tech
  • World Tech
  • World Tech Code

Recent Posts

  • How Casino Projects are Created and Who Supplies Its Components May 20, 2022
  • How To Break Into Working In Tech May 20, 2022
  • A Creative Guide to Services and Solutions Offered at eSoft May 20, 2022
  • Why You Need To Consider Asia Pulp & Paper May 20, 2022

Categories

  • Fitness Trackers
  • General
  • Latest
  • Tech
  • Technology and Computing
  • Wearable Tech
  • World Tech
  • World Tech Code

© 2022 FeedBuzzard.com

No Result
View All Result
  • Fitness Trackers
  • General
  • Tech
  • Wearable Tech
  • World Tech
  • World Tech Code
  • Contact Us

© 2022 JNews - Premium WordPress news & magazine theme by Jegtheme.