In this post we will learn how to implement dropdownlist with inline selectlist in MVC 5.
lets start by creating action method in controller
add a view for this action method and write the following code
Now Rebuild the application and run
In this post we will learn how to Implement nested dropdownlist with model binding in MVC 5
Here I am going to implement nested dropdown with country, state and city example. To get Country, state and cities data I am writing three methods called GetCountries(), GetStates(int CountryId) and GetCities(int StateId)
Here GetCountries method is accepting no parameters and it will return Countries selectlist. GetStates is accepting a parameter countryId of type int and it will return States selectlist, GetCities is accepting a parameter StateId of type int and it will return Cities selectlist
After preparing data elements, let’s get into the implementation
first create model as follows
In this Model we have 3 list members and 3 primitive members
Now add 2 Action methods in the controller one is for GET call and another is for POST call
Now add a view for the action method and write the following code in it
In the view we are using onchange event for dropdownlist to submit the form and gets the states and cities list on demand.
Now Rebuild the application and run.
In this post we will learn how to validate Dropdownlist using Model in MVC 5
First create model as follows
In the model we have added the following line
Required is a attribute applied on SelectedCountryId.
this Required attribute is available in the namespace
Required attribute force the user to send SelectedCountryId to the server, otherwise it will display the error message mentioned in the model as follows
Now write the action method in controller as follows
Add the view for the above action method and write the following code in it.
Now rebuild the application and Run
In this post we will learn how to implement simple Dropdown list with model binding and selectlist in MVC 5.
Let’s create Model as follows
Now add a controller and add the following action method in it
Now add the view and write the following code:
Now rebuild the application and run
In this post we will learn How to implement Checkbox list in mvc 5 with model
First create Model as follows
Now let’s create action method in controller class
Now lets create Editor Template for the player model as follows:
first create a folder with name “EditorTemplates” under Views folder for your controller
Write the following code in that Editor Template
Now create a view for the current action method
Now Rebuild the application and Run.
In this post we will learn how to implement Radiobutton list control with enum in mvc 5
Let’s sart by creating Enum for favourite subjects
next prepare model as follows
lets create action method in controller as follows.
We can implement view in different ways
Method 1: Radiobutton list with foreach loop
Method 2: Simple Radiobutton list
Now rebuild the project and run