asp.net mvc tutorial for beginners
Lección 191 de 496 · Part 37 Generating a radiobuttonlist control in mvc using HTML helpers · Bases de datos
Part 37 Generating a radiobuttonlist control in mvc using HTML helpers
Text version of the video
http://csharp-video-tutorials.blogspot.com/2013/06/part-37-generating-radiobuttonlist.html
Slides
http://csharp-video-tutorials.blogspot.com/2013/09/part-37-generating-radiobuttonlist.html
All ASP .NET MVC Text Articles
http://csharp-video-tutorials.blogspot.com/p/aspnet-mvc-tutorial-for-beginners.html
All ASP .NET MVC Slides
http://csharp-video-tutorials.blogspot.com/p/aspnet-mvc-slides.html
All Dot Net and SQL Server Tutorials in English
https://www.youtube.com/user/kudvenkat/playlists?view=1&sort=dd
All Dot Net and SQL Server Tutorials in Arabic
https://www.youtube.com/c/KudvenkatArabic/playlists
In this video, we will discuss, generating a radiobuttonlist control in mvc using Html.RadioButtonFor helper. Please watch Part 36 before proceeding.
Right click on the “Models” folder and add a class file with “name=Company.cs”. Copy and paste the following code.
public class Company
{
public string SelectedDepartment { get; set; }
public List[Department] Departments
{
get
{
SampleDBContext db = new SampleDBContext();
return db.Departments.ToList();
}
}
}
Copy and paste the following 2 “Index” action methods in HomeController class.
[HttpGet]
public ActionResult Index()
{
Company company = new Company();
return View(company);
}
[HttpPost]
public string Index(Company company)
{
if (string.IsNullOrEmpty(company.SelectedDepartment))
{
return “You did not select any department”;
}
else
{
return “You selected department with ID = ” + company.SelectedDepartment;
}
}
Right click on the “Index” action method in “HomeController” and add a view with “name=Index”. Copy the index view code from by blog using the link below.
http://csharp-video-tutorials.blogspot.com/2013/06/part-37-generating-radiobuttonlist.html
Run the application and click on “Submit” without selecting any department. Notice that, you get a message stating you have not selected any department. On the other hand, select a department and click “Submit”. The selected department ID must be displayed.