In this article, we are going to learn how to perform a CRUD operation in Lotus Notes via ASP MVC.
Previously, I have posted an article "How to get data from Lotus Notes through ASP MVC" . To know about this, refer to Getting Data From Lotus Notes Through ASP MVC
(Note: The viewers are asked to read the previous article, because we are continuing the same model and controller here).
In the last article, we learned how to get the data from Lotus Notes view and displayed it in ASP MVC list.

Here, our model is StudentDetails.
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- namespace LotusNotesTOASPMvc.Models
- {
- public class StudentDetails
- {
- public string UNID { get; set; }
- public string StudentName { get; set; }
- public double Age { get; set; }
- public string City { get; set; }
- public string Address { get; set; }
- public string PhoneNo { get; set; }
- }
- }
Our controller is "StudentInformationsController".
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.Mvc;
- using Domino;
- using LotusNotesTOASPMvc.Models;
- namespace LotusNotesTOASPMvc.Controllers
- {
- public class StudentInformationsController : Controller
- {
- NotesSession session = new NotesSession();
- NotesDatabase db;
- NotesView view;
- NotesDocument doc;
- public ActionResult Index()
- {
- session.Initialize("password@#123");
- db = session.GetDatabase("", "Migration.nsf", false);
- view = db.GetView("vwStudentInformations");
- doc = view.GetFirstDocument();
- List<StudentDetails> student = new List<StudentDetails>();
- while(doc!=null)
- {
- string UNID = doc.UniversalID;
- string Name = doc.GetItemValue("txName")[0];
- double Age = doc.GetItemValue("txAge")[0];
- string City = doc.GetItemValue("txCity")[0];
- string Address = doc.GetItemValue("txAddress")[0];
- string PhoneNo = doc.GetItemValue("txPhoneNo")[0];
- student.Add(new StudentDetails
- {
- UNID=UNID,
- StudentName=Name,
- Age=Age,
- City=City,
- Address=Address,
- PhoneNo=PhoneNo
- });
- doc = view.GetNextDocument(doc);
- }
- return View(student);
- }
- }
- }
CREATE Document
Now, we will see how to create a document in Lotus Notes via ASP MVC.
If a user clicks a Create link in list, we have to redirect a page to create form. Before clicking a create link first we have to design a form.To create a form, follow the below steps,
Step 1
Create new ActionResult in our controller and name it as "Create"
Create new ActionResult in our controller and name it as "Create"
- [HttpGet]
- public ActionResult Create()
- {
- return View();
- }
Step 2
Create a view for action. Right click on Create Action ->select Add view -> Select Template Create and Select your model ->Click OK.
Create a view for action. Right click on Create Action ->select Add view -> Select Template Create and Select your model ->Click OK.
Now, your view will be generated. Build the Application and run it.
- @model LotusNotesTOASPMvc.Models.StudentDetails
- @{
- ViewBag.Title = "Create";
- }
- <h2>Create</h2>
- @using (Html.BeginForm())
- {
- @Html.AntiForgeryToken()
- <div class="form-horizontal">
- <h4>StudentDetails</h4>
- <hr />
- @Html.ValidationSummary(true)
- <div class="form-group">
- @Html.LabelFor(model => model.StudentName, new { @class = "control-label col-md-2" })
- <div class="col-md-10">
- @Html.EditorFor(model => model.StudentName)
- @Html.ValidationMessageFor(model => model.StudentName)
- </div>
- </div>
- <div class="form-group">
- @Html.LabelFor(model => model.Age, new { @class = "control-label col-md-2" })
- <div class="col-md-10">
- @Html.EditorFor(model => model.Age)
- @Html.ValidationMessageFor(model => model.Age)
- </div>
- </div>
- <div class="form-group">
- @Html.LabelFor(model => model.City, new { @class = "control-label col-md-2" })
- <div class="col-md-10">
- @Html.EditorFor(model => model.City)
- @Html.ValidationMessageFor(model => model.City)
- </div>
- </div>
- <div class="form-group">
- @Html.LabelFor(model => model.Address, new { @class = "control-label col-md-2" })
- <div class="col-md-10">
- @Html.EditorFor(model => model.Address)
- @Html.ValidationMessageFor(model => model.Address)
- </div>
- </div>
- <div class="form-group">
- @Html.LabelFor(model => model.PhoneNo, new { @class = "control-label col-md-2" })
- <div class="col-md-10">
- @Html.EditorFor(model => model.PhoneNo)
- @Html.ValidationMessageFor(model => model.PhoneNo)
- </div>
- </div>
- <div class="form-group">
- <div class="col-md-offset-2 col-md-10">
- <input type="submit" value="Create" class="btn btn-default" />
- </div>
- </div>
- </div>
- }
- <div>
- @Html.ActionLink("Back to List", "Index")
- </div>
- @section Scripts {
- @Scripts.Render("~/bundles/jqueryval")
- }
Step 3
Now, you can click the create link. It will redirect to create a form.

Step 4
We have to post the form details to controller to save the data in Lotus Notes. Create ActionResults in controller to receive the data from view.
Now, you can click the create link. It will redirect to create a form.

Step 4
We have to post the form details to controller to save the data in Lotus Notes. Create ActionResults in controller to receive the data from view.
- [HttpPost]
- public ActionResult Create(StudentDetails studentDetails)
- {
- session.Initialize("password@#123");
- db = session.GetDatabase("", "Migration.nsf", false);
- doc = db.CreateDocument();
- doc.ReplaceItemValue("Form", "StudentInformations");
- doc.ReplaceItemValue("txName", studentDetails.StudentName);
- doc.ReplaceItemValue("txAge", studentDetails.Age);
- doc.ReplaceItemValue("txCity", studentDetails.City);
- doc.ReplaceItemValue("txAddress", studentDetails.Address);
- doc.ReplaceItemValue("txPhoneNo", studentDetails.PhoneNo);
- doc.Save(true, false);
- return RedirectToAction("Index", "StudentInformations");
- }


Edit document
To edit the document, follow the steps given below.
Step 1
Create an ActionResult with a parameter and name it as EDIT.
Create an ActionResult with a parameter and name it as EDIT.




Join the conversation! Your thoughts help the community grow.