In this article I will explain with an example, how to insert (save) Hindi, Marathi, Gujarati, Urdu, Persian, Arabic, Tamil and Telugu languages Text characters in SQL Server database in ASP.Net MVC.
Note: For beginners in ASP.Net MVC, please refer my article ASP.Net MVC Hello World Tutorial with Sample Program example.
 
 

Database

I have made use of the following table Languages with the schema as follow.
Content column is specified with NVARCHAR data type for saving Hindi, Marathi, Gujarati, Urdu, Persian, Arabic, Tamil and Telugu languages Text characters.
ASP.Net MVC: Insert Hindi, Marathi, Gujarati, Urdu, Persian, Arabic, Tamil and Telugu languages Text characters in Sql Database
 
Note: You can download the database table SQL by clicking the download link below.
           Download SQL file
 
 

Installing Newtonsoft package using Nuget

In order to install Newtonsoft library using Nuget, please refer my article Installing Newtonsoft library using Nuget.
 
 

Model

The Model class consists of following properties.
public class LanguageModel
{
    public string Language { get; set; }
    public string Content { get; set; }
}
 
 

Namespaces

You will need to import the following namespaces.
using Newtonsoft.Json;
using System.Data.SqlClient;
 
 

Controller

The Controller consists of following Action methods.

Action method for handling GET operation

Inside this Action method, simply the View is returned.
 

Action method for handling Post operation

Inside this Action method, the JSON string is received from the View.
The JSON string is deserialized into Generic List of LanguageModel class objects.
Then loop I executed over the Generic List of LanguageModel class objects and one by one it is inserted into the SQL Server database table.
Finally, the Generic List of LanguageModel class objects is returned to the View.
public class HomeController : Controller
{
    public ActionResult Index()
    {
        return View();
    }
 
    [HttpPost]
    public ActionResult Index(string languageJSON)
    {
        List<LanguageModel> languages = JsonConvert.DeserializeObject<List<LanguageModel>>(languageJSON);
        string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
        string query = "INSERT INTO LanguagesVALUES(@Language, @Content)";
        using (SqlConnection con = new SqlConnection(constr))
        {
            con.Open();
            foreach (LanguageModel language in languages)
            {
                using (SqlCommand cmd = new SqlCommand(query, con))
                {
                    cmd.Parameters.AddWithValue("@Language", language.Language);
                    cmd.Parameters.AddWithValue("@Content", language.Content);
                    cmd.ExecuteNonQuery();
                }
            }
            con.Close();
        }
        return View(languages);
    }
}
 
 

View

HTML Markup

The View consists of an HTML Table, a Form with an HiddenField and a Button.
The HTML Table is created with some rows containing text in different languages.
The Button has been assigned with a JavaScript onclick event handler.
 
Inside the View, following jQuery file is inherited.
1. jquery.min.js
 

JavaScript Implementation

Inside the Save JavaScript function, first a JavaScript Array is created. Then the HTML Table is referenced and then a for loop is executed over its rows.
Inside the for loop, a JSON object is created for storing the Language and Content values.
Note: It is very important that the properties of the Language JSON object and the LanguageModel must be exact same.
 
The Language JSON object is then pushed into the Languages JavaScript Array.
Finally, the JSON object is serialized into a string and saved into a Hidden Field and the Form is submitted.
@model List<Insert_Languages_SQL_MVC.Models.LanguageModel>
@{
     Layout = null;
}
 
<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Index</title>
</head>
<body>
    <table id="tblLanguages" cellpadding="0" cellspacing="0">
        <tr>
            <th>Language</th>
            <th>Content</th>
        </tr>
        <tr>
            <td>English</td>
            <td>World isbeautiful.</td>
        </tr>
        <tr>
            <td>Hindi</td>
            <td>दुनिया सुंदर है।</td>
        </tr>
        <tr>
            <td>Marathi</td>
            <td>जग सुंदर आहे.</td>
        </tr>
        <tr>
            <td>Gujarati</td>
            <td>વિશ્વ સુંદર છે.</td>
        </tr>
        <tr>
            <td>Urdu</td>
            <td>دنیا خوبصورت ہے.</td>
        </tr>
        <tr>
            <td>Persian</td>
            <td>جهانی زیبااست.</td>
        </tr>
        <tr>
            <td>Arabic</td>
            <td>العالم هوجميل.</td>
        </tr>
        <tr>
            <td>Tamil</td>
            <td>உலக அழகாக இருக்கிறது.</td>
        </tr>
        <tr>
            <td>Telugu</td>
            <td>ప్రపంచ అందమైన ఉంది.</td>
        </tr>
    </table>
    <hr />
    @using (Html.BeginForm("Index", "Home", FormMethod.Post))
    {
        <input type="hidden" name="languageJSON" value="" />
        <input type="button" value="Save" onclick="Save()" />
    }
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
    <script type="text/javascript">
        function Save() {
            var languages = [];
            var tblLanguages = $("#tblLanguages");
            for (var i = 1; i < tblLanguages[0].rows.length; i++) {
                var row = tblLanguages[0].rows[i];
                var language = {};
                language.Language = row.cells[0].innerText;
                language.Content = row.cells[1].innerText;
                languages.push(language);
            }
            $("[name=languageJSON]").val(JSON.stringify(languages));
            document.forms[0].submit();
        }
    </script>
</body>
</html>
 
 

Screenshots

The GridView

ASP.Net MVC: Insert Hindi, Marathi, Gujarati, Urdu, Persian, Arabic, Tamil and Telugu languages Text characters in Sql Database
 

The inserted records in the database table

ASP.Net MVC: Insert Hindi, Marathi, Gujarati, Urdu, Persian, Arabic, Tamil and Telugu languages Text characters in Sql Database
 
 

Downloads