Binding DropDownListFor from enum, database and some hard coded values in our previous article [MVC dropdown binding best ways][1]. In this article we will try to bind child Dropdown on selection change of parent Dropdown, say Country to State or Sate to City, by using jQuery which will call an action in controller and return JSON for selected id, and with the help of jQuery append values to...
By Ali Adravi
On 11 Apr 2015
Viewed: 145,108

CRUD (Create, Retrieve, Update and Delete) in MVC. When we start to learn new language, first we try to run an application with “Hello World” and then CRUD functionality. So in this article we will see how to select records from database (with WebGrid, pagination and sort functionality), update a record, add new record and finally delete a record in ASP.Net MVC.
Let’s create a simple table...
By Ali Adravi
On 17 Aug 2013
Viewed: 97,285

Search, sort, paging, insert, update and delete with ASP.Net MVC and bootstrap modal popup and WebGrid to show records with search, sort and paging feature and in next article we will complete our article by adding insert, update and delete feature with bootstrap modal popup. We are going to use Entity Framework 6 code first model with a very simple table phone. Adding client side sorting and...
By Ali Adravi
On 28 Dec 2014
Viewed: 53,939

To Bind a DropDownListFor or DropDown in asp.net MVC from database, from enum or from hard coded values, most people suggest to add a property in the model with IEnumarable or IList. We can use it but not very helpful because after every postback we will need to fill the list again otherwise it will be null. So using ViewBag is not a bad idea, we will use it in our article.
What we will see...
By Ali Adravi
On 04 Apr 2015
Viewed: 43,485

To add insert, update and delete feature we are going to use bootstrap modal popup with a single JavaScript method to open any partial view as a modal popup and one method to post the data from modal, which can work for entire application. First we will add some code to our layout view to dynamically add the partial view in it and JavaScript file, then we will add code only one for add new...
By Ali Adravi
On 28 Dec 2014
Viewed: 42,284

MVC Searh page with pagination:
It’s very easy to create a search page in asp.net but when I try to create the same in MVC I faced many problems, how to create model, how to keep searched values in search controls, pagination, I found myself nowhere, so start searching for some good examples but whatever I found was not quite helpful so try my own. I will explain the same in this...
By Ali Adravi
On 25 Aug 2013
Viewed: 35,052

Image gallery in asp.net mvc or in any other language can be achieved by using different free JavaScript libraries. What we need for a good image gallery, at least we need images in two sizes to show thumbnail and then the original image on clicking the image. In this article we will write a small method to calculate the new image size and save images in multiple sizes. To upload image we will...
By Ali Adravi
On 10 Jan 2015
Viewed: 27,809

Uploading image to database is not a normal practice but in some situations we need it, in my [previous blog][1] many people request to write to store the image into database, first of all, I would like to thanks for all those emails and interest in my blogs and site. I am going to change the database structure a little bit but use the same modal to post the data from view to controller which...
By Ali Adravi
On 03 Aug 2015
Viewed: 25,886

We are going to use ng-grid with feature like searching, sorting and paging of records, we will use paginated data, means pull only as many records as we have to show into our ng-grid. We already discussed about the AngularJS application structure in our previous article see [ASP.Net MVC Web API AngularJS and Bootstrap application structure][3]. We will use Entity Framework and WebAPI to search...
By Ali Adravi
On 30 Nov 2014
Viewed: 22,538

Upload multiple files with model data in MVC is really very easy, when I started to test by uploading some files, I though it would be more complicated but it is really not. In my previous post [ASP.Net MVC file upload][1], I promised to post soon about how to upload multiple files. When I was writing I thought why cannot add model data as well at the time of uploading the files.
We will...
By Ali Adravi
On 04 Jun 2013
Viewed: 22,498

First of all we will try for multiple field search with paging and sorting for products by using WebGrid. We will create relationship between products and category table so we can show the category name in grid. To search we need a separate model for search having all the paging, sorting, total records and products. We need full featured page to search records by providing product name, price and...
By Ali Adravi
On 22 Mar 2015
Viewed: 21,683

In MVC we have EnumDropDownListFor which we can directly bind with our any enum, it is very similar to DropDownListFor. In this article we will try to create an enum and use it into our model and see how we can bind and save it into the database. As we know we cannot keep space in the name of emum members so how we can use a clear text into dropdown than the enum members. It is easy we will use...
By Ali Adravi
On 15 May 2015
Viewed: 18,067

MVC webgrid searh page with pagination:
There are many benefits of using WebGrid in place of table like paging, sorting and alternate row style etc., in our previous article we see [MVC search page example with code][1] but there we used table to create the structure of gridview which is missing sorting and alternate row functionality. In this article we will use WebGrid and check how easy it is...
By Ali Adravi
On 25 Aug 2013
Viewed: 17,559

Uploading file with other model data, validate model & file before uploading by using DataAnnotation is a tricky part because there is no FileFor or any similar control in MVC. So very first question comes in mind, is that possible to use DataAnnotation with file control? Yes, it is very possible. Second question, it this possible with client side validation, even the answer is yes.
We know...
By Ali Adravi
On 28 Mar 2015
Viewed: 14,709

Razor provides all the option to format the data as well as conditional attributes, even it is more powerful than we had earlier in asp.net. In this article we will try to see some commonly used conditional attribute tricks, formatting of data like apply class conditionally, show hide controls, enable and disable the controls. How to use icons as link in WebGrid, add HTML to the column,...
By Ali Adravi
On 14 Mar 2015
Viewed: 13,922

Application structure by using ASP.Net MVC, Web API, AngularJs is not complicated but we need to know what NuGet Packages are required and what can make the application easy and speed up the development. In this article we will use MVC 4, Visual Studio 2012, Web API and AngularJS to create a single page application. We will try to use different folders for keeping our controllers, services,...
By Ali Adravi
On 17 Nov 2014
Viewed: 9,589

How to upload file or image in asp.net mvc is not difficult but is totally different compare to asp.net FileUpload control. If we are asp.net developer and we are new to mvc then we immediately noticed we don’t have server side controls so the FileUpload control as well and our problem start here. Now we start searching how to upload a file if there is no FileUpload control, no problem whatever...
By Ali Adravi
On 25 May 2013
Viewed: 7,301

Add, enable, disable dates to datepicker control is really more than easy but I found most beginners struggle with it to add datepicker with a control or to enable and disable dates for a particular condition. In this article we will learn how to add datepicker without any calendar icon as well as with calendar icon. Disable dates which are less than today's date, disable dates which are greater...
By Ali Adravi
On 15 Mar 2015
Viewed: 6,518

In MVC, autocomplete with jquery is the best way to pull data from database and render according to our requirements, so in this article we will use jquery to show the auto complete text box without any ajax controls. We need a method to get the data from database, a controller method to handle the action and a jquery/javascript function to call the controller method.
Note: we will use...
By Ali Adravi
On 29 Jun 2013
Viewed: 6,053

Adding calendar with a text box for new MVC developer is not so easy, I always found in my team people struggle to add a calendar with a text box, while it is as easy as jut to add one line of code and done. It’s true, when first time I try to add a calendar with a text box I also searched many website, read blogs and found, I need to add many jquery files from different locations before using...
By Ali Adravi
On 03 Feb 2013
Viewed: 5,890