This article explains how to create a simple registration form with Kendo Panel Bar using WEB API 2 and Entity Framework 5.

Just create a Web API project as shown in Figures 1 & 2.


Figure 1

Figure 2

I am using the Entity Framework Code First technique to connect with the database.

Create a model class and name it Registration.

Use the following code in that class:

  1. public class Registration
  2. {
  3. [Key]
  4. [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
  5. public int UserID { get; set; }
  6. [Required]
  7. public string FirstName { get; set; }
  8. public string MiddleName { get; set; }
  9. [Required]
  10. public string LastName { get; set; }
  11. [Required]
  12. public string UserName { get; set; }
  13. }
Create one more model class and name it RegistrationContext.

Use the following code in that class:

  1. public class RegistrationContext:DbContext
  2. {
  3. public RegistrationContext() : base("name=TestConnection") { }
  4. public DbSet<Registration> RegisterUser { get; set; }
  5. }
Modify your connection string in the web config file.
  1. <connectionStrings>
  2. <add name="TestConnection" connectionString="Data Source=your SQL server Name;Initial Catalog=Your Database Name;Integrated Security=True" providerName="System.Data.SqlClient" />
  3. </connectionStrings>

Build your project once to start scaffolding.

Add a controller as shown in Figures 3, 4 & 5.


Figure 3

Figure 4

Figure 5

The following step will scaffold the REST full service in the Registration controller.

You will get some pre-defined HTTP GET, POST, PUT and DELETE request/responses in Registrations Controller. Modify the code based on your application requirements. For this example I did not change the code.

To insert a record into the registration table we should use HTTP POST request/response.

Before implementing it in the UI we will check it in POST MAN as shown in Figure 6.

Figure 6


Design the UI to consume the REST HTTP POST service.

I have used the Kendo UI to Desgin with MVVM Pattern.

Here is my design:

  1. <!DOCTYPE html>
  2. <html
  3. xmlns="http://www.w3.org/1999/xhtml">
  4. <head>
  5. <title></title>
  6. <script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js'></script>
  7. <link rel="stylesheet" href="http://cdn.kendostatic.com/2014.3.1316/styles/kendo.common.min.css" />
  8. <link rel="stylesheet" href="http://cdn.kendostatic.com/2014.3.1316/styles/kendo.default.min.css" />
  9. <link rel="stylesheet" href="http://cdn.kendostatic.com/2014.3.1316/styles/kendo.dataviz.min.css" />
  10. <link rel="stylesheet" href="http://cdn.kendostatic.com/2014.3.1316/styles/kendo.dataviz.default.min.css" />
  11. <script src="http://cdn.kendostatic.com/2014.3.1316/js/jquery.min.js"></script>
  12. <script src="http://cdn.kendostatic.com/2014.3.1316/js/kendo.all.min.js"></script>
  13. <script src="Js/RegisterViewModel.js"></script>
  14. </head>
  15. <body>
  16. <div id="example">
  17. <div id="RegistrationForm" class="demo-section k-header">
  18. <div class="container">
  19. <h4>Simple Registration Page Using Kendo Panel Bar</h4>
  20. <ul data-role="panelbar"
  21. style="width: 1130px">
  22. <li>
  23. <span>Personal Details</span>
  24. <div class="row">
  25. <div class="col-lg-3">
  26. <label for="fname">First Name:</label>
  27. </div>
  28. <div class="col-lg-3">
  29. <input id="fname" data-bind="value: firstName" class="k-textbox" required />
  30. </div>
  31. <div class="col-lg-3">
  32. <span class="k-invalid-msg" data-for="fname"></span>
  33. </div>
  34. </div>
  35. <div class="row">
  36. <div class="col-lg-3">
  37. <label for="mname">Middle Name:</label>
  38. </div>
  39. <div class="col-lg-3">
  40. <input id="mname" data-bind="value: MiddleName" class="k-textbox" />
  41. </div>
  42. </div>
  43. <div class="row">
  44. <div class="col-lg-3">
  45. <label for="lname">Last Name:</label>
  46. </div>
  47. <div class="col-lg-3">
  48. <input id="lname" data-bind="value: lastName" class="k-textbox" required />
  49. </div>
  50. </div>
  51. </li>
  52. <!--Second Pane Login Infomation-->
  53. <li>
  54. <span>Login Information</span>
  55. <div class="row">
  56. <div class="col-lg-3">
  57. <label for="UserName">User Name*:</label>
  58. </div>
  59. <div class="col-lg-3">
  60. <input id="UserName" data-bind="value: UserName" class="k-textbox" required />
  61. </div>
  62. </div>
  63. <div class="row">
  64. <div class="col-lg-3">
  65. <label for="password">Password*:</label>
  66. </div>
  67. <div class="col-lg-3">
  68. <input required type="password" id="Password" data-bind="value: Passsword" class="k-textbox" />
  69. </div>
  70. </div>
  71. <div class="row">
  72. <div class="col-lg-3">
  73. <label for="ConfirmPwd">Confirm Password*:</label>
  74. </div>
  75. <div class="col-lg-3">
  76. <input required type="password" id="ConfirmPwd" data-bind="value: ConfirmPwd" class="k-textbox" />
  77. </div>
  78. </div>
  79. </li>
  80. </ul>
  81. <input type="submit" id="btn_Submit1" value="Submit" class="k-button" onclick="RegisterUser()" />
  82. </div>
  83. </div>
  84. </div>
  85. </body>
  86. </html>

In browser as show in Figure 7,


Figure 7

MVVM Model script
  1. $(document).ready(function() {
  2. var viewModel = kendo.observable({
  3. firstName: null,
  4. MiddleName: null,
  5. lastName: null,
  6. UserName: null,
  7. isVisible: true,
  8. })
  9. kendo.bind($("#example"), viewModel);
  10. });
  11. function RegisterUser() {
  12. $.ajax({
  13. cache: false,
  14. async: false,
  15. type: "POST",
  16. url: "http://localhost:64955/api/Registrations",
  17. data: {
  18. FirstName: $("#fname").val(),
  19. MiddleName: $("#mname").val(),
  20. LastName: $("#lname").val(),
  21. UserName: $("#UserName").val()
  22. },
  23. success: function(data) {
  24. //alert(data);
  25. if (data == 'True') {
  26. ret = false;
  27. uploadWindow.close();
  28. window.location = SubmitURL;
  29. } else ret = true;
  30. },
  31. error: function(jqXHR, exception) {
  32. alert(errorHandling(jqXHR, exception));
  33. }
  34. });
  35. }

Insert a record using the Kendo UI Panel bar as shown in Figure 8.


Figure 8

Check your database table.

Hooray! The records are inserted.

That's it, enjoy coding.