ASPMANTRA | Asp.Net,MVC,AngularJs,Jquery,Javascript,Sql Server AND WCF snippets and tutorial

Sql Server: how to change the state of database


In this article I am going to explain how to change the state (Read only to Read Write and vice versa) of Sql server database.

Description:
While working on window form application, I have face the issue of read only database on data insert.

Solution:
To resolve this issue we have 2 ways. One using Sql server management studio and 2nd one using Sql query.

Asp.net MVC : Implement infinite scroll using Jquery

Here in this article I am going to explain how to implement infinite scroll using Jquery in asp.net MVC application.

Description:
I am showing list of country in application. Instead of pagination want to show all records on scroll. To fulfill this requirement I am using Jquery.

Implementation:

Model class:
   public partial class CountryMaster
    {
        public int ID { get; set; }
        public string Name { get; set; }
        public string CountryCode { get; set; }
    }

Add Controller
Add an empty controller to project.

Complete source code of Controller:

MVC : Cascading DropdownList

Introduction: In this article today I am going to explain how we can Populate Cascading Dropdown List in Asp.net MVC4 using Json and Jquery
Populate Cascading Dropdown
(Click to Enlarge)
Description:

I want to populate State dropdown on Country selection and on State Dropdown Selection populate City dropdown. I have three classes in model CountryState and City.
Country:
using System.ComponentModel.DataAnnotations;

public class Country
    {
        [Key]
        public int CountryId { getset; }
        public string CountryName { getset; }

        public virtual ICollection<State> States { getset; }
    }

State:

Hello world application with Angular 6


Here in this tutorial I am going to explain how to create hello world application with Angular 6.

Prerequisite 

a.  Visual studio code
b.  Node.js

You can download the latest version of Visual studio code from here and Node.js from here.
Node.js installation will also install the npm. After installation start the visual studio code. If you see the message of Git is missing then you have to install the git to your system. You can download latest version here or in visual studio code  there is link in message to download git, when you click on the link it will redirect you to download link.

How to change password in MVC application


In this article I am going to explain how to change password in MVC application. 

Description:
I want to add change password functionality for logged in users. To change password users have to enter current password, after that new password and confirm the new password.
  

Implementations:
Please check the previous post Create login form and maintain authenticated user’s detail in MVC application.

Model

How to generate numeric and alphanumeric OTP (one time password) in MVC application


Here in this article I am going to explain how to generate numeric and alphanumeric OTP (one time password) in MVC application.

Description:
I want to generate OTP. OTP can be numeric or alphanumeric and it is used widely to validate the user’s information such as mobile number, in banks for transaction etc.

Implementation:

Add controller
Add an empty controller to project. Create 3 action to generate OTP, one to generate numeric and 2nd one alphanumeric.
Generate random password in MVC application

Generate random password in MVC application


In this article I am going to explain how to generate random password in MVC application.


Description:
I want to generate strong random password for users when they registers to website. Here in this article I am going to generate password using 2 ways.


Implementation:
Add an empty controller to project. I have create action Generatepassword.

  public ActionResult Generatepassword()
        {
            return View();
        }

Using Membership Generate method
ASP.NET MVC : Display data in 2 or more columns

ASP.NET MVC : Display data in 2 or more columns


In this article I am going to explain how to display data in 2 or more columns in MVC application.

Description:
I want to display data in 3 columns. To display data 2 or more columns we have 2 approaches. One use the Bootstarp, if use the bootstrap it adjust itself. 2nd one using the loop, run the loop and differentiate them like odd and even. For 2nd one check this article.

Implementation:
Model

MVC : Generate random OTP (one time password)


In this article I am going to explain how to generate random OTP (one time password) in asp.net MVC application.

Description:
I want to generate OTP. OTP can be numeric or alphanumeric and it is used widely to validate the user’s information such as mobile number, in banks for transaction etc.

Implementation:

Add controller
Add an empty controller to project. Create 3 action to generate OTP, one to generate numeric and 2nd one alphanumeric.

Complete code of controller:

How to show data in 2 columns in MVC application


In this article I am going to explain how to show data in 2 columns in MVC application.

Description:
I am displaying list of all countries in MVC application one record per row but I want to display data in 2 columns. 2 records pre row.

Implementations:

Model

How to crop image using Iedit Jquery in MVC application

In this article I am going to explain how to crop image using Iedit Jquery and save to folder in MVC application.

Description:
In MVC application, want to add functionality to crop the image. When user’s uploading profile image, they can crop the uploaded image and it will be save to image folder. I am using IEdit Jquery plugin to crop the profile image. You can download the IEdit Jquery from here.

Implementation:
Add Controller:
Add an empty controller to project. Create action to upload profile pic.

Convert Image to Base64 string and Base64 string to Image in asp.net MVC application

In this article I am going to explain how to convert Image to Base64 string and Base64 string to Image in asp.net MVC application.

Description:
In MVC application want to convert Image to Base64 and Base64 encoded string to Image.

Implementation:
Add empty controller to project. Create method to convert Image and Base64 encoded string.

Complete code to Controller :

ASP.NET MVC : Crop image and save cropped image to folder

In this article I am going to explain how to crop image and save cropped image to folder in MVC using Jquery.

Description:
In MVC application, want to add functionality to crop the image. When user’s uploading profile image, they can crop the uploaded image and it will be save to image folder. I am using IEdit Jquery plugin to crop the profile image. You can download the IEdit Jquery from here.

Implementation:

Add Controller:

SQL SERVER : Create database from .MDF & .LDF file

In this article I am going to explain how to create database from .MDF & .LDF file in Sql server.

Description & Implementation:
I have .MDF and .LDF file of database. I want to restore or create database from these files. We have 2 ways to create database from .MDF and .LDF file.

Method 1: Using  T-Sql
Run the below given query :

How to display username of logged in users in MVC application

In this artic article I am going to explain how to display username of logged in users in MVC application.

Description:
In MVC project I have created login form. After successfully logged in, want to show users name on top right hand side. I am using Tempdata to maintain the user’s detail.

Implementation:

ASP.NET : Get Month name, number, year and number of days from given date

In this article I am going to explain how to get Month name, number, year and number of days from selected date in asp.net.


Description:
I want to get the month name, number, year and number of days in selected month.

Implementation:

HTML markup of webform:

Create login form and maintain authenticated user’s detail in MVC application

In this artic article I am going to explain how to create login form and maintain authenticated user’s detail in MVC application.

Description:
I want to create login form and maintain the authenticated user’s detail in application. I am using Tempdata to maintain the user’s detail.

Implementation:

Model:

Check Password strength using Jquery in MVC application

In this article I am going to explain how to check Password strength using Jquery in MVC application. 

Description:
I want to show the strength of password entered by users or admin. I am using Jquery to show password’s strength.

Implementation:

Upload file’s on button click using Dropzone JS plugin in asp.net application

In this article I am going how to upload file’s on button click using Dropzone JS plugin in asp.net application.

Description:
I want to upload multiple files using select or drag & drop in asp.net application on submit button click. I am using Dropzone js to upload file.

Implementation:
I have created a table GalleryImages to save file’s name and path.

Id
int
Filename
varchar(MAX)
FilePath
varchar(MAX)
Is_Deleted
bit

Create procedure to save detail to database table.

How to send email with attachment using Gmail SMTP from asp.net MVC application

In this article I am going to explain how to send email with attachment using Gmail SMTP from asp.net MVC application.

Description:
I want to send email with attachment using Gmail account.

Implementation:
Open the web.config file of project. Set key in Appsettings. After that mailsettings as shown below:
<appSettings>
    <add key="Email" value="Emailaddress@gmail.com"/>
  </appSettings>
  <system.net>
    <mailSettings>
      <smtp deliveryMethod="Network">
        <network enableSsl="true" port="587" host="smtp.gmail.com" userName=" Emailaddress@gmail.com" password="password"/>
      </smtp>
    </mailSettings>
  </system.net>

MVC : Send email with attachment

In this article I am going to explain how to send email with attachment using Gmail account in MVC application.

Description:
I want to send email with attachment using Gmail account.

Implementation:

Open the web.config file of project. Set key in Appsettings. After that mailsettings as shown below:
<appSettings>
    <add key="Email" value="Emailaddress@gmail.com"/>
  </appSettings>
  <system.net>
    <mailSettings>
      <smtp deliveryMethod="Network">
        <network enableSsl="true" port="587" host="smtp.gmail.com" userName=" Emailaddress@gmail.com" password="password"/>
      </smtp>
    </mailSettings>
  </system.net>