In this article I will explain with an example, how to insert (save) Hijri Date in SQL Server Database table using ASP.Net MVC.
	
		 
	
		 
	
		Database
	
		I have made use of the following table IslamicEvents with the schema as follows.
	
	
		 
	
		
			Note: You can download the database table SQL by clicking the download link below.
		
	 
	
		 
	
		 
	
		Model
	
		The following Model class consists of two properties.
	
		
			public class IslamicEventModel
		
			{
		
			    public string EventName { get; set; }
		
			    public string HijriDate { get; set; }
		
			}
	 
	
		 
	
		 
	
		Namespaces
	
		You will need to import the following namespaces.
	
		
			using System.Configuration;
		
			using System.Data.SqlClient;
	 
	
		 
	
		 
	
		Controllers
	
		The Controller consists of following two Action methods.
	
		Action method for handling GET operation
	
		Inside this Action method, simply the View is returned.
	
		 
	
		Action method for handling POST operation
	
		The Action method for POST operation accepts IslamicEventModel as Parameter. The values posted from the Form inside the View are received through this parameter.
	
		The received values are then inserted into the SQL Server database table.
	
		
			public class HomeController : Controller
		
			{
		
			    // GET: Home
		
			    public ActionResult Index()
		
			    {
		
			        return View();
		
			    }
		
			 
		
			    [HttpPost]
		
			    public ActionResult Index(IslamicEventModel islamicEvent)
		
			    {
		
			        string constring = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
		
			        using (SqlConnection con = new SqlConnection(constring))
		
			        {
		
			            using (SqlCommand cmd = new SqlCommand("INSERT INTO IslamicEvents VALUES (@Event, @Date)", con))
		
			            {
		
			                cmd.Parameters.AddWithValue("@Event", islamicEvent.EventName);
		
			                cmd.Parameters.AddWithValue("@Date", islamicEvent.HijriDate);
		
			                con.Open();
		
			                cmd.ExecuteNonQuery();
		
			                con.Close();
		
			            }
		
			        }
		
			 
		
			        return RedirectToAction("Index");
		
			    }
		
			}
	 
	
		 
	
		 
	
		View
	
		Inside the View, in the very first line the IslamicEventModel class is declared as model for the View.
	
		The View consists of an HTML Form which has been created using the Html.BeginForm method with the following parameters.
	
		ActionName – Name of the Action. In this case the name is Index.
	
		ControllerName – Name of the Controller. In this case the name is Home.
	
		FormMethod – It specifies the Form Method i.e. GET or POST. In this case it will be set to POST.
	
		Inside the HTML Form there are two TextBox field created for capturing value for Event name and Hijri date and a Submit Button.
	
		The TextBoxes are created using the Html.TextBox method of HTML Helper class.
	
		 
	
		Implementing Bootstrap Hijri DatePicker plugin
	
		Inside the 
jQuery document ready event handler, the 
HijriDate TextBox has been applied with the 
Bootstrap Hijri DatePicker plugin.
 
	
	
		 
	
		Form Submit
	
		When the Submit Button is clicked the form is submitted to the Controllers Action Method.
	
		
			@model Hijri_Date_Insert_MVC.Models.IslamicEventModel
		
			@{
		
			    Layout = null;
		
			}
		
			 
		
			<!DOCTYPE html>
		
			 
		
			<html>
		
			<head>
		
			    <meta name="viewport" content="width=device-width" />
		
			    <title>Index</title>
		
			</head>
		
			<body>
		
			    @using (Html.BeginForm("Index", "Home", FormMethod.Post))
		
			    {
		
			        <div class="container">
		
			            <div class="row">
		
			                <div class="col-md-12">
		
			                    <label>Event</label>
		
			                    <div class="input-group">
		
			                        @Html.TextBox("eventName", "", new { @id = "txtEvent", @class = "form-control" })
		
			                    </div>
		
			                </div>
		
			                <div class="col-md-12">
		
			                    <label>Date</label>
		
			                    <div class="input-group">
		
			                        @Html.TextBox("hijriDate", "", new { @id = "txtHijriDate", @class = "form-control" })
		
			                    </div>
		
			                </div>
		
			                <div class="col-md-12">
		
			                    <br/>
		
			                    <input type="submit" id="btnSubmit" value="Submit" class="btn btn-primary" />
		
			                </div>
		
			            </div>
		
			        </div>
		
			    }
		
			 
		
			    <link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" />
		
			    <link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.47/css/bootstrap-datetimepicker.min.css" rel="stylesheet" />
		
			   <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
		
			    <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.1/moment.min.js"></script>
		
			    <script src="https://cdn.jsdelivr.net/npm/moment-hijri@2.1.0/moment-hijri.js"></script>
		
			    <script src="~/assets/js/bootstrap-hijri-datetimepicker.js"></script>
		
			    <script type="text/javascript">
		
			        $(function () {
		
			            $("#txtHijriDate").hijriDatePicker();
		
			        });
		
			    </script>
		
			</body>
		
			</html>
	 
	
		 
	
		 
	
		Screenshots
	
		The Form
	
	
		 
	
		Date inserted in Table
	
	
		 
	
		Downloads