Irwsoft NETCore Asp

Working with FormData
Brief Information
DescriptionInformation about how to work with FormData tag-helper in data-entry application.
Form tag-helper
FormData tag-helper in Insert mode

Form tag-helper
FormData tag-helper in View mode

Form tag-helper
Image preview in View mode

This page will give you brief information about how to work with INA - FormData tag-helper. The first thing declares the property-names and its data-type. Please note that data-type is important to specify the input tag-helper. The other thing to define all actions/events of the FormData tag-helper with related action name of specific controller.

The FormData tag-helper has three modes. The View mode displays plain table to display data only with Edit or Insert buttons. The Insert mode gives you blank entry data with Save or Cancel buttons. The Edit mode gives you entry data to edit current data object with Save or Cancel buttons. So the last thing is specified the DataMode of the FormData which represents as the beginning state when FormData displays in View, Edit or Insert mode.

Example : Input registration data of ID Card in Person table with FormData

C# code for Person table

// 1) Sample code for Person table
public class Person
     public int ID { get; set;}
     public string FirstName { get; set;}
     public string LastName { get; set;}
     public GenderType Gender { get; set;}
     public DateTime DateOfBirth { get; set;}
     public int Age { get; set;}
     public string Address { get; set;}
     public string City { get; set;}
     public string Country { get; set;}
     public string IdentityCardNo { get; set;}
     public string BioData { get; set;}
     public string PictureUrl { get; set;}

ASPX code for Form

// 1) Defines the FormData tag-helper
<FormData ID="FR1" runat="server" SkinStyle="GreenOcean" DataObject=Model
     FormLayoutMode="Table" ColumnCount="3" LabelWidth="150" DataWidth="250"
     CancelController="FormData" CancelAction="Index" EditController="FormData" EditAction="Edit"
     InsertController="FormData" InsertAction="Insert" SaveController="FormData" SaveAction="Save"
     ImagePreviewController="FormData" ImagePreviewAction="ImagePreview"
     FileDownloadController="FormData" FileDownloadAction="FileDownload"
     FileDeleteController="FormData" FileDeleteAction="Delete"
     FileSaveController="FormData" FileSaveAction="Save">
          <div style="width: 100%;"text-align: center;">Identity Card Registration Form</div>
     <FormDataPropertyName Name="FirstName" Caption="First Name" />
     <FormDataPropertyName Name="LastName" Caption="Last Name" />
     <FormDataPropertyName Name="DateOfBirth" Caption="Date of Birth"
               DataType="Date" Format="dd/MM/yyyy" AllowEmpty="false" />
     <FormDataPropertyName Name="Age" DataType="Integer" />
     <FormDataPropertyName Name="Gender" DataType="List" Type="SamplesNET2.Data.GenderType"
     <FormDataPropertyName Name="IdentityCardNo" Caption="ID No." />
     <FormDataPropertyName Name="Address" />
     <FormDataPropertyName Name="City" />
     <FormDataPropertyName Name="Country" />
     <FormDataPropertyName Name="PictureUrl" Caption="Photo" DataType="ImageUrl" AllowEmpty="false" />
     <FormDataPropertyName Name="BioData" Caption="Bio Data" DataType="MultiText" />
          <div style="width: 100%;"text-align: right;"></div>

C# code behind for Form state

// 1) Index action where all begin.
public IActionResult Index()
     Person dataPerson = new Person();
     // 1.1) Fill the properties of person data ...
     return View(dataPerson);

// 2) Edit action prepares data to edit
public IActionResult Edit(int personID)
     Person dataPerson = RetrievePerson(personID);
     return View("Index", dataPerson);

// 3) Insert action prepares insert process
public IActionResult Insert(FormDataActionArgs formAction)
{    // 3.1) Populate the data from FR1 tag-helper !
     return View("Index");

// 4) Save action persist data to database
public IActionResult Save(Person dataPerson)
     return View("Index", dataPerson);

C# code behind to handle file upload/delete

// 5) Delete file action
public JsonResult FileDelete(FileUploadDeleteArgs e)
{    // 5.1) Delete file in the FileName of the argument !
     return Json("Delete file completed !");

// 6) Upload file action
public JsonResult FileSave(FileUploadSaveArgs e)
{    // 6.1) Get file stream from File of the argument !
     System.IO.Stream stream = a.File.OpenReadStream();
     // 6.2) Persist file binary in a disk or database !
     return Json("Save file completed !");

C# code behind to handle file download or image preview

// 7) Image preview action
public JsonResult ImagePreview(FileClientProviderArgs e)
{    // 7.1) Return the URL of the image !
     return Json("/images/female.jpg");

// 8) File download action
public FileContentResult FileDownload(FileClientProviderArgs e)
{    // 8.1) Load data in an array of byte !
     byte[] contents = System.IO.File.ReadAllBytes(@"E:\...wwwroot\images\female.jpg");
     FileContentResult r = new FileContentResult(contents, "image/jpg");
     r.FileDownloadName = "attachment;filename=Person.jpg";
     // 8.2) Return the filecontent !
     return r;

C# code behind handles all database process with Irwsoft Data Framework

// 1) Handles database persistence in SaveToDatabase method
private void SaveToDatabase(Person data)
{    // 1.1) Persist the data using Irwsoft Data Framework !
     SqlInsertInto insert = new SqlInsertInto(data);
     insert.ConnectionString = "Your connection string here ...";

Related Topics :

Irwsoft Data Ultimate Edition 4.0 supports data-schema extension (entity framework, linq to sql, simple class, and etc).