245,587 views 199 on YTPak
336 3

Published on 11 May 2013 | over 4 years ago

Text version of the video
csharp-video-tutorials.blogspot.com/2013/05/part-12-creating-view-to-insert-data.html

Slides
csharp-video-tutorials.blogspot.com/2013/09/part-12-creating-view-to-insert-data.html

All ASP .NET MVC Text Articles
csharp-video-tutorials.blogspot.com/p/aspnet-mvc-tutorial-for-beginners.html

All ASP .NET MVC Slides
csharp-video-tutorials.blogspot.com/p/aspnet-mvc-slides.html

All Dot Net and SQL Server Tutorials in English
www.youtube.com/user/kudvenkat/playlists

All Dot Net and SQL Server Tutorials in Arabic
www.youtube.com/c/KudvenkatArabic/playlists

In this video we will discuss, creating a view to insert a new employee into the database table tblEmployee. Please watch Part 11, before proceeding with this video.

We want to present the end user with a form to enter data.

Copy and paste the following "Create" action method, in EmployeeController class.
[HttpGet]
public ActionResult Create()
{
return View();
}

Please note that, the method is decorated with "HttpGet" attribute. This makes this action method to respond only to the "GET" request.

Now let's add a "Create" view. To do this, right click on the "Create" action method and select "Add View" from the context menu. Set
1. View name = "Create"
2. View engine = "Razor"
3. Select "Create Strongly-typed view checkbox
4. Select "Employee" class, from "Model class" dropdownlist
5. Scaffold Template = Create
6. Click "Add" button

At this point "Create.cshtml" view will be added in "Employee" folder. If you have the following "Scripts" section at the bottom of the view, please delete it. We will discuss about sections and scripts in a later video session.
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}

Run the application and navigate to the following URL
"http://localhost/MVCDemo/Employee/Index"

Click on "Create New" link. You will be naviaged to the following URL
"http://localhost/MVCDemo/Employee/Create"

A form with textboxes to add a new employee is rendered. For employee "Gender" it is ideal to have a dropdownlist instead of a text box.

Run the application and notice that, a dropdownlist is now displayed for "Gender".

If you click on "Create" button, you will get an error message stating - The resource cannot be found. This is because we donot have the "Create" controller action method that can handle HTTPPost request. We will discuss fixing this in our next video.
Customize Your Hybrid Embed Video Player!

6-digit hexadecimal color code without # symbol.

 

Report video function is under development.

 


Loading related videos...